CSC448: Code Generation Revisited: Exceptions [126/133] |
The traditional solution to dealing with exceptional cases is to distinguish normal values from exceptional values, and to require every piece of code to check for exceptional values. However, this is neither robust nor manageable, even in modestly sized systems, nor is it appropriate for processing asynchronous errors.
Exceptions provide a control-flow mechanism that is quite different from other control-flow constructs found in common languages.
Exceptions provide a form of non-local jump where the destination is unknown: we must provide an exception name and the runtime system will jump to the most recent exception handler block that we are currently inside.
In addition, the runtime system may:
Throwable
in Java.
finally
blocks in Java.
Some examples:
There are many tricky details:
RuntimeException
or Error
, e.g.,
you need need not declare ArrayStoreException
or SecurityException
everywhere.
f (e1, e2)
,
e2
has a side-effect, and e1
throws an exception? Is there a guaranteed order of
evaluation?