Download presentation
Presentation is loading. Please wait.
Published byBarnaby Cain Modified over 9 years ago
1
CIS 270—Application Development II Chapter 13—Exception Handling
2
2 13.1-3 Introduction & Overview An exception is an indication of a problem during program ___________. A program that ________ exceptions keeps running. Interjecting program logic with error-handling logic in a program creates maintenance problems. If an exception occurs and is not handled, it is _________. The error message produced by Java is called a stack _______, which consists of the exception name and the method-call stack. You can trace an exception starting at the top.
3
3 13.4 Handling Exceptions 1 If you don’t want a method to handle an exception, you should code a ________ clause at the end of the method declaration. A throws clause can list one or more exceptions. To handle an exception, you should enclose the code that could throw an exception in a _____ block. Code that handles the exception is placed immediately after the try block in a _______ block. A try block must be followed by at least one catch block or a finally block. A catch block can handle only one kind of exception.
4
4 13.4 Handling Exceptions 2 When an exception occurs in a try block, control is passed to the appropriate catch block, after which control resumes after the _______ catch block. This is called the ___________ model because the try block is terminated (instead of resuming in the try block after the exception is handled). A try ___________ is the combination of the try block and all catch and finally blocks. If an exception occurs, the method or try block terminates and local variables go out of _______ and are destroyed.
5
5 13.6 Java Exception Hierarchy 1 The Throwable class has two subclasses: Exception and Error It is usually not possible for a program to recover from Error s (such as out of __________). All Java exception classes inherit from Exception. The Exception class has two subclasses: RuntimeException and IOException. ___________ exceptions are only those that inherit from RuntimeException, such as division by 0. All others are checked exceptions, which MUST be thrown or handled (or program will not _________).
6
6 13.6 Java Exception Hierarchy 2 The Java compiler checks your code for the possibility of checked exceptions and will force you to catch or throw (________) such exceptions. __________ exceptions (like division by 0) can be prevented by proper coding and do not need to be listed in a throws clause. catch blocks must be ordered with subclass exceptions coming _______ superclass exceptions (or else you will lose specific exception information).
7
7 13.7 finally Block If data files are not closed by a program, they may not be available to other programs. This is an example of a __________ leak. A finally block is placed after the last catch block. The finally block will always execute unless a try block calls ____________. A finally block usually contains resource- ___________ code. The output stream System.err allows the programmer to deal with error messages separately.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.