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!

12.1      Exceptions in Java

 
 

12.1.1    A taste of exceptions

 

12.1.2    Why handle exceptions separately?

 
 

12.1.3    Does exception handling offer any other benefits?

 
 
 

12.2      Categories of exceptions

 
 
 

12.2.1    Identifying exception categories

 
 
 

12.2.2    Class hierarchy of exception classes

 
 

12.2.3    Checked exceptions

 

12.2.4    Runtime exceptions

 

12.2.5    Errors

 
 

12.3      Creating a method that throws an exception

 
 

12.3.1    Create a method that throws a checked exception

 
 
 

12.3.2    Handle-or-declare rule

 

12.3.3    Creating a method that throws runtime exceptions or errors

 
 

12.3.4    A method can declare to throw all types of exceptions, even if it doesn’t

 
 
 

12.4      What happens when an exception is thrown?

 
 
 

12.4.1    Creating try-catch-finally blocks

 
 
 

12.4.2    Using a method that throws a checked exception

 
 
 

12.4.3    Using a method that throws a runtime exception

 
 
 
 

12.4.4    Using a method that throws an error

 
 

12.4.5    Will a finally block execute even if the catch block defines a return statement?

 
 
 

12.4.6    What happens if both a catch and a finally block define return statements?

 

12.4.7    What happens if a finally block modifies the value returned from a catch block?

 
 
 

12.4.8    Can a try block be followed only by a finally block?

 
 
 

12.4.9    Does the order of the exceptions caught in the catch blocks matter?

 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest