19.11.2014 Views

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 14<br />

Exceptions<br />

Exceptions are values that can be thrown and caught, via throw expressions (described in Section 13.25) and catch<br />

clauses of try expressions (described in Section 13.26). When a throw expression “throw e ” is evaluated, the<br />

subexpression e is evaluated to an exception. <strong>The</strong> static type of e must be a subtype of Exception. <strong>The</strong>n the throw<br />

expression tries to transfer control to its dynamically containing block (described in Chapter 4), from the innermost<br />

outward, until either (i) an enclosing try expression is reached, with a catch clause matching a type of the thrown<br />

exception, or (ii) the outermost dynamically containing block is reached.<br />

If a matching catch clause is reached, the right-hand side of the first matching subclause is evaluated. If no matching<br />

catch clause is found before the outermost dynamically containing block is reached, the outermost dynamically<br />

containing block completes abruptly whose cause is the thrown exception.<br />

If an enclosing try expression of a throw expression includes a finally clause, and the try expression completes<br />

abruptly, the finally clause is evaluated before control is transferred to the dynamically containing block.<br />

14.1 Causes of Exceptions<br />

Every exception is thrown for one of the following reasons:<br />

1. A throw expression is evaluated.<br />

2. An implementation resource is exceeded (e.g., an attempt is made to allocate beyond the set of available locations).<br />

14.2 Types of Exceptions<br />

All exceptions have type Exception declared as follows:<br />

trait Exception comprises { CheckedException, UncheckedException }<br />

settable message: MaybeString<br />

settable chain: MaybeException<br />

printStackTrace():()<br />

end<br />

Every exception has either type CheckedException or UncheckedException:<br />

118

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

Saved successfully!

Ooh no, something went wrong!