Introducing ExceptionsAn exception is an event that disrupts the normal flow of execution in a program. Some of the advantages of using exceptions are:
- Separating error-handling code from regular code
- Easily differentiating error types
- Being able to propagate errors up the call stack
For the exam, you should be familiar with the following concepts:
|Call Stack||List of methods that had been called to get to the method where the error occurred|
|Exception Handler||A block of code that can handle the exception. If the runtime system doesn’t find an appropriate exception handler in the call stack to catch the exception, it terminates the thread throwing the exception|
Kind of ExceptionsThere are two groups of exceptions:
As it’s shown in the previous table, an unchecked exception can be either an
Error or a
The Throwable Family
It could seem that the table below just shows some examples of Java exception classes, but it doesn’t. It actually shows the minimum exception class hierarchy you should be familiar to:
Throwable (the base class, the father of all exceptions), its two sons (
Exception) and its main grandchildren. Trust me when I tell you that you should learn the content of this table before trying to do the exam.
(JVM or Application)
To learn more about exceptions and how to deal with them read the lesson about catching and handling exceptions.