catch

The catch keyword designates exceptions that are caught if thrown.

Purpose

This keyword is used within a try statement to designate exceptions that are caught if thrown.

Context

Functions or rule actions

Syntax

try {statements} 
catch (exceptionType1 identifier) {statements} 
[catch (exceptionType2 identifier) {statements} 
...]
finally {statements}

Description

The try-catch-finally statements establish a block of code for exception handling. Such blocks all begin and end with curly braces.

The catch statements are designed to handle a specific type of exception. The code within a catch statement is executed if an exception is caught. A catch statement is declared with an exceptionType that specifies the type of exception that the statement can handle. It also provides an identifier that the statement can use to refer to the exception object that it is currently handling. The identifier must be of type Throwable or one of its subclasses.