JavaBeginner#exceptions

What is a custom exception and how do you create one?

A user-defined exception class extending Exception (checked) or RuntimeException (unchecked), used to represent domain-specific error conditions with more meaningful names and data.

Example
class InsufficientFundsException extends RuntimeException {
  InsufficientFundsException(String msg) { super(msg); }
}
throw new InsufficientFundsException("Balance too low");

Related Questions

1
JavaIntermediate#exceptions

What is exception chaining (cause)?

Open
2
JavaBeginner#exceptions

What is the order of execution for try, catch, and finally?

Open
3
JavaAdvanced#exceptions

What happens if an exception is thrown in a finally block?

Open