13. Exception Handling

Objectives

In this chapter you’ll learn:

• How exception and error handling works.

• To use try, throw and catch to detect, indicate and handle exceptions, respectively.

• To use the finally block to release resources.

• How stack unwinding enables exceptions not caught in one scope to be caught in another scope.

• How stack traces help in debugging.

• How exceptions are arranged in an exception-class hierarchy.

• To declare new exception classes.

• To create chained exceptions that maintain complete stack-trace information.

It is common sense to take a method and try it. If it fails, admit it frankly and try another. But above all, try something.

Franklin Delano Roosevelt

O! throw away the worser part of it, And live ...

Get Java™ for Programmers: Deitel now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.