Checked Exception
Eine Checked Exception ist eine Exception in Java, die der Compiler dich zwingt zu behandeln.
Entweder
try/catchoderthrowsim Methoden-Signatur.
I. Beispiele
IOExceptionSQLExceptionClassNotFoundExceptionNamingException
II. Achtung bei CMT
Denk-Falle 8 (siehe Enterprise Java Bean)
Eine Checked Exception löst bei CMT keinen Rollback aus. Wenn du Rollback willst:
throw new RuntimeException(...)daraus machen- ODER
@ApplicationException(rollback = true)auf deine eigene Exception setzen
III. Behandlung
public void doStuff() throws IOException { // option 1: weiterreichen
// ...
}
public void doStuff() { // option 2: fangen
try { /* ... */ }
catch (IOException e) { /* ... */ }
}
IV. .NET-Vergleich
.NET hat keine Checked Exceptions — alle Exceptions sind unchecked.