10.12.2012 Views

The Java Language Specification, Third Edition

The Java Language Specification, Third Edition

The Java Language Specification, Third Edition

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

14.20 <strong>The</strong> try statement BLOCKS AND STATEMENTS<br />

396<br />

synchronized(t) {<br />

synchronized(t) {<br />

System.out.println("made it!");<br />

}<br />

}<br />

}<br />

}<br />

prints:<br />

made it!<br />

This example would deadlock if a single thread were not permitted to lock a lock<br />

more than once.<br />

14.20 <strong>The</strong> try statement<br />

<strong>The</strong>se are the times that try men’s souls.<br />

. . . and they all fell to playing the game of catch as catch can,<br />

till the gunpowder ran out at the heels of their boots.<br />

—<br />

A try statement executes a block. If a value is thrown and the try statement has<br />

one or more catch clauses that can catch it, then control will be transferred to the<br />

first such catch clause. If the try statement has a finally clause, then another<br />

block of code is executed, no matter whether the try block completes normally or<br />

abruptly, and no matter whether a catch clause is first given control.<br />

TryStatement:<br />

try Block Catches<br />

try Block Catchesopt Finally<br />

Catches:<br />

CatchClause<br />

Catches CatchClause<br />

CatchClause:<br />

catch ( FormalParameter ) Block<br />

Finally:<br />

finally Block<br />

DRAFT

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!