14.18
The
try
statement
BLOCKS AND STATEMENTS
14.18 The
try
statement
These are the times that try men's souls.
Thomas Paine
, The American Crisis
(1780)
. . . and they all fell to playing the game of catch as catch can,
till the gunpowder ran out at the heels of their boots.
Samuel Foote
A
try
statement executes a block. If a value is thrown and the
try
statement has
one or more
catch
clauses that can catch it, then control will be transferred to the
first such
catch
clause. If the
try
statement has a
finally
clause, then another
block of code is executed, no matter whether the
try
block completes normally or
abruptly, and no matter whether a
catch
clause is first given control.
TryStatement:
try
Block Catches
try
Block Catches
opt
Finally
Catches:
CatchClause
Catches CatchClause
CatchClause:
catch (
FormalParameter
)
Block
Finally:
finally
Block
The following is repeated from 8.4.1 to make the presentation here clearer:
FormalParameter:
Type VariableDeclaratorId
The following is repeated from 8.3 to make the presentation here clearer:
VariableDeclaratorId:
Identifier
VariableDeclaratorId
[ ]
The
Block
immediately after the keyword
try
is called the
try
block of the
try
statement. The
Block
immediately after the keyword
finally
is called the
finally
block of the
try
statement.
A
try
statement may have
catch
clauses (also called
exception handlers
).
A
catch
clause must have exactly one parameter (which is called an
exception
290
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Inexpensive Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Jsp Hosting
Cheap Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved