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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.