Exception Handling

Jenkov java-exception-handling

Definitions

Java Exception Handling: enables your Java applications to handle errors.

Call stack: is the sequence of method calls from the current method and back to the Main method of the program.

In Java, there are two types of exceptions:

1. Checked Exceptions must be explicitly caught (try-catch) or propagated (throws). Extend the java.lang.Exception class.

  • ClassNotFoundException
  • IOException
  • SQLException

2. UnChacked Exceptions don’t have to be caught or declared thrown. Extend the java.lang.RuntimeException. Some examples:

  • ArithmeticException
  • ArrayStoreException

Checked and Unchecked Exceptions are functionally equivalent!

Java Errors: indicates a serious problem that an application should not try to catch. Errors are the conditions that cannot be recovered by any handling technique. Errors are unchecked (occur at runtime) and defined in java.lang.Error. Some error examples:

  • java.lang.StackOverflow
  • java.lang.OutOfMemoryError

Exception Hierarchy

Exception Hierarchy

Basic Exception Handling