Java Exceptions

This collection of articles teaches you all about exceptions in Java.

  1. Java Exceptions: Throw, Try and Catch
    This article explains what exceptions are, including related concepts such as throwing, propagating and catching.
  2. Java Exception Types
    This article explains the difference between the various exception types offered by the Java API.
  3. Chained Exceptions
    Chained exceptions, or wrapped exceptions, are used to indicate that a lower level exception was the cause for a higher level exception.
  4. Custom Exception
    This page explains and provides examples for how to implement user defined custom exceptions.
  5. Difference between Checked and Unchecked Exceptions
    This article explains what the difference between checked and unchecked exceptions are.
  6. Choosing between Checked and Unchecked Exceptions
    When is it appropriate for a method throw an exception? Should it be checked or unchecked? This article answers these questions in depth, provides examples and a quick flowchart for future reference.
  7. Checked Exceptions: Good or Bad?
    Are checked exceptions a good language feature? Or is it a failed experiment where Java is the first and last language to support it? This article describes the pros and cons and explains why it's often misused and when it's a perfect fit.
  8. Return Values vs Exceptions
    When should a method throw an exception, and when should it use a return value to indicate an error? This article answers the question in detail and provides concrete examples.
  9. try + finally
    A finally block follows a try block and is always executed, regardless if the try block finishes normally or exceptionally.
  10. try-with-resources
    The try-with-resources feature is used to automatically close a file or other resource, no matter the outcome of a previous operation. It's a convenient way of guaranteeing that a state will be restored such as a resource being released.
  11. Stack Traces
    A stack trace describes the state of a thread. It says which methods have been called (but not yet returned) and is often used to debug problems.
  12. Suppressed Exceptions
    Suppressed exceptions are primarily used to deal with exceptions that are suppressed in a try-with-resource construct.
  13. throw vs throws vs Throwable
    This article explains the difference between three similar Java terms: throw, throws and Throwable
  14. List of Java Exceptions
    This page provides a complete list of all public exceptions and errors available in the Java API, grouped by package.