[Previous] [Contents] [Next]

Basic Exception-Handling Syntax


Exception handling consists of only four keywords: try, catch, throw, and finally. The way the keywords work is simple and straightforward. When a method fails its objective and cannot continue-that is, when it detects an exceptional situation-it throws an exception to the calling method by using the throw keyword. The calling method, assuming it has enough context to deal with the exception, then receives this exception via the catch keyword and decides what course of action to take. In the following sections, we'll look at the language semantics governing how to throw and catch exceptions as well as some code snippets that will illustrate how this works.

[Previous] [Contents] [Next]