Hallo,
ich habe ein Programm, in dem eine "unchecked exception " ArrayIndexOutOfBoundsException geworfen wird. Die wird durch den catch-block(RuntimeException) gefangen. Wenn ich einen zusätzlichen catch-block mit NullPointerException aufnehmen, gibt es schon ein Problem beim Kompilieren(der ist überflüssig). Für mich ist nur fraglich wieso der Kompiler macht keine Problemme bei den catch-blöcken: Exception,Throwable? In meinem try-block werfe ich doch keine Exception oder Throwable.
ich habe ein Programm, in dem eine "unchecked exception " ArrayIndexOutOfBoundsException geworfen wird. Die wird durch den catch-block(RuntimeException) gefangen. Wenn ich einen zusätzlichen catch-block mit NullPointerException aufnehmen, gibt es schon ein Problem beim Kompilieren(der ist überflüssig). Für mich ist nur fraglich wieso der Kompiler macht keine Problemme bei den catch-blöcken: Exception,Throwable? In meinem try-block werfe ich doch keine Exception oder Throwable.
Code:
public class SupExp {
public final static synchronized strictfp void main(String... s) {
try {
throw new ArrayIndexOutOfBoundsException();
} catch (RuntimeException e) {
System.out.print("GotoA, ");
} catch (NullPointerException e) {
System.out.print("GotoB, ");
} catch (Exception e) {
System.out.print("GotoC, ");
} catch (Throwable e) {
System.out.print("GotoD, ");
}
}
}