Wenn ich ein Programm wie das folgenden habe:
... können sowohl charAt eine IndexOutOfBoundsException und der Socketkonstruktor eine Illegal...Exception.
Warum fordert der Compiler bei letzerem eine Behandlung der Exception (also eine try-catch Anweisung) und bei ersterem nicht?
Code:
import java.net.*;
public class Main{
public static void main(String[] args) {
char c = "hallo".charAt(2);
try{
Socket s = new Socket("localhost", 4711);
}
catch(Exception e){}
}
}
... können sowohl charAt eine IndexOutOfBoundsException und der Socketkonstruktor eine Illegal...Exception.
Warum fordert der Compiler bei letzerem eine Behandlung der Exception (also eine try-catch Anweisung) und bei ersterem nicht?