World 12 of 26 · Intermediate

💥 Exceptions & Errors

15 Java concepts, each explained step by step with real code, a common trap and practice questions.

  1. The Throwable hierarchyThrowable → Error / Exception → RuntimeException.
  2. Checked vs uncheckedChecked must be handled or declared; unchecked need not be.
  3. try / catchCatching exceptions, catch order from specific to general.
  4. Multi-catchcatch (A | B e) and the rule about related types.
  5. finallyAlways runs (except System.exit/JVM crash); return in finally overrides.
  6. throw vs throwsthrow raises an exception; throws declares it in a signature.
  7. Custom exceptionsExtending Exception or RuntimeException, adding context.
  8. try-with-resourcesAutoCloseable resources closed automatically in reverse order.
  9. Suppressed exceptionsExceptions from close() attached via getSuppressed().
  10. Exception chainingWrapping causes with new X(msg, cause); getCause.
  11. Reading a stack traceFinding the origin line and the Caused by section.
  12. Common runtime exceptionsNPE, ClassCast, IllegalArgument, IllegalState, NumberFormat, IndexOutOfBounds, UnsupportedOperation, ConcurrentModification.
  13. Errors you should not catchOutOfMemoryError, StackOverflowError and why.
  14. Exception best practicesNever swallow, fail fast, don't use exceptions for flow control, preserve the cause.
  15. Assertionsassert statements, disabled by default, enabled with -ea.