RuntimeException
RuntimeException ist eine unchecked Exception in Java.
Muss nicht im Methoden-Signatur deklariert werden — der Compiler zwingt dich nicht.
I. Beispiele
NullPointerExceptionIllegalArgumentExceptionArithmeticExceptionIndexOutOfBoundsException
II. Verhalten bei CMT
In Jakarta EE mit CMT:
- RuntimeException = automatischer Rollback ✓
- Checked Exception = KEIN Rollback (Default!)
@Stateless
public class FooService {
public void doIt() {
throw new RuntimeException("oops");
// → Container rollbackt die TX automatisch
}
}
III. Unterschied zu Checked
| RuntimeException | Checked Exception | |
|---|---|---|
Compiler erzwingt try/catch? |
❌ | ✅ |
throws im Signatur? |
optional | Pflicht |
| Rollback bei CMT? | ✅ | ❌ |