ERights Home elang / blocks 
Back to: The 'while' Expression On to: The 'switch' Expression

The try Expressions


This should be immediately familiar at least to C++ and Java programmers. Let's call the "try" keyword and the scope-box which follows a "try clause". Similarly, we'll refer to a "catch clause" and a "finally clause". A try-expression must begin with one try-clause, may then have zero or more catch clauses, and optionally end with a finally clause. The try-expression first evaluates the attempt-expression. If this completes normally, then the value of the try-expression is the value of the attempt-expression. However, before the try-expression completes, the exit-expression, if any, is evaluated. Besides completing normally, there are three abnormal ways an expression might terminate:

  1. With a thrown Throwable. If the attempt terminates this way, the try-expression searches in order for the first matching exception-pattern. If it finds one, then evaluation continues with the corresponding handler expression. The outcome of this handler-expression is the outcome of the try-expression. If no exception-pattern matches, the Throwable is rethrown

  2. By calling an escape hatch.

In all cases, the exit-expression, if any, is evaluated as the last action before leaving the try-expression. If the exit-expression itself terminates abnormally, then its termination takes priority over whatever form of termination we were engaged in.

 
Unless stated otherwise, all text on this page which is either unattributed or by Mark S. Miller is hereby placed in the public domain.
ERights Home elang / blocks 
Back to: The 'while' Expression On to: The 'switch' Expression
Download    FAQ    API    Mail Archive    Donate

report bug (including invalid html)

Golden Key Campaign Blue Ribbon Campaign