Ich habe versucht, dieses Stück Code ohne Internetverbindung zu laufen, erwarten und IOException auslösen:IOException Java
import java.net.*;
import java.io.*;
public class API_connect {
public static void main(String[] args) {
try {
URL API = new URL("http://api.football-data.org");
URLConnection API_connection = API.openConnection();
}
catch(MalformedURLException exception) {
System.out.print(exception);
}
catch(IOException exception) {
System.out.print(exception);
System.out.print("is something going on here?");
}
}
}
Und gut ... Zu meiner Überraschung nichts gedruckt wurde, und ich kann nicht herausfinden, Warum. Wäre nicht ein Mangel an Internetverbindung der Hauptgrund, warum hier eine IOException ausgelöst wird?
Beim Drucken von Ausnahmen bevorzuge ich im Allgemeinen [printStackTrace()] (https://docs.oracle.com/javase/8/docs/api/java/lang/Throwable.html#printStackTrace--) – phflack