Custom Exception in Java
A custom exception is your own error type: class AgeException extends Exception { ... }. Use it when a business rule fails (age < 0, balance too low) and you want a clear name.
Extend Exception for checked (caller must handle). Extend RuntimeException for unchecked. Give a constructor that takes a message: super(msg).
Don’t invent a custom exception for every tiny check. Use it when the name helps the caller.
Let's take this on the board with one tiny Main class — no extra files. Output: Asha scored 72 then Pass. Real Main. Swap marks/name to show one idea from Custom Exception in Java. Start from main, go line by line, and stop at each print. That output is the proof for Custom Exception.
try { risky }
│ throws
▼
catch → message
│
▼
finally → cleanupWrite class AgeException extends Exception { AgeException(String m) { super(m); } } then throw it.