12 Exception handling
Exam objectives covered in this chapter |
What you need to know |
[11.1] Describe the advantages of Exception handling and differentiate among checked exceptions, unchecked exceptions, and Errors |
The need for and advantages of exception handlers. |
[11.3] Create and invoke a method that throws an exception |
How to create methods that throw exceptions. Rules that cover when overriding or overridden methods throw or don’t throw exceptions. How to determine the flow of control when an invoked method throws an exception. How to apply this to cases when one is thrown without a try block and from a try block (with appropriate and insufficient exception handlers). The difference in calling methods that throw or don’t throw exceptions. |
[11.2] Create a try-catch block and determine how exceptions alter normal program flow |
How to create a try-catch-finally block. Understand the flow of code when the enclosed code throws an exception or error. How to create nested try-catch-finally blocks. |
Imagine you’re about to board an airplane to Geneva to attend an important conference. At the last minute, you learn that the flight has been cancelled because the pilot isn’t feeling well. Fortunately, the airline quickly arranges for an alternative pilot, allowing the flight to take off at its originally scheduled time. What a relief!