Layers of Logic

Phase XII

When Things Go Wrong

Diagnosing failures, reading stack traces, and designing exception handling.

2 sections41 min of reading8 exercises

Read stack traces and distinguish compile-time errors from exceptions thrown while a program runs. Use try, catch, finally, and try-with-resources, then choose checked, unchecked, or custom exception types from the caller's recovery options.

When you finish this phase you can

  • Read a stack trace from the failure location through its callers and causes
  • Explain what separates an Error from an Exception and why broad catches are unsafe
  • Explain checked and unchecked exceptions, and the argument against checked ones
  • Use try-with-resources and explain resource closing and suppressed exceptions
  • Write a custom exception that carries the information the caller needs
  • Explain what happens to a pending exception when finally returns
  1. 12.1Exceptions, Errors, and the Stack TraceDistinguish normal returns from thrown failures, read a stack trace from the failure outward, and use try, catch, finally, and try-with-resources.ExceptionStack traceCore20 min4 exercises
  2. 12.2Checked, Unchecked, and Exceptions of Your OwnDistinguish checked exceptions, unchecked exceptions, and errors, then design custom exceptions that preserve useful causes and recovery choices.Checked exceptionCore21 min4 exercises