Exception handling mechanisms have become an essential tool for software development. Since exceptions are propagated automatically by the language support, methods need to be aware only of the particular exceptions they can handle locally. This degree of obliviousness is particularly useful in a context where exceptions are bound to arise not only to report logical errors but also as a response to environmental failures (e.g. long-lasting disconnection).
The motivation for an ambient-oriented exception handling mechanism stems from the fact that traditional try-catch-based exception handling mechanisms cannot be reconciled with a programming model based on non-blocking communication as prescribed by the AmOP paradigm. This combination yields a set of concrete problems which are addressed by the ambient-oriented exception handling mechanism.
try-catch
associates exception handlers with a particular position on the runtime stack. However, since communication is non-blocking, the runtime stack may have been altered substantially by the time the exception is reported. As a consequence, the exception may not be handled properly if at all. This problem can be circumvented by attributing handler blocks to futures (actor placeholders for the result to be computed). AmbientTalk therefore has adopted the when-catch
construct from the E programming language.when-catch
construct, which allows handling exceptions on a per-message basis, additional support is needed to support protecting an entire block of code with a set of exception handlers (as with a try-catch
block). When the block of code consists of various messages being sent asynchronously, each message may concurrently raise an exception. AmbientTalk allows dealing with these concurrent exceptions through the group
construct which implicitly groups all returned futures and allows specifying how to handle an ensemble of concurrently raised exceptions.conversation
to which all partners listen for reported exceptions and to whom exceptions are signalled implicitly.
The design of the exception handling model is closely coupled with the design of the futures abstraction of which it is a natural extension. The ambient-oriented exception handling relies allowing futures to be ruined transitively by exceptions, in combination with the introduction of the when-catch
construct described above. The group
and conversation
constructs capture recurrent - and conceptually idiosyncratic - patterns of use of this basic abstraction.
Ambient-Oriented Exception Handling, Stijn Mostinckx, Jessie Dedecker, Elisa Gonzalez Boix, Tom Van Cutsem, Wolfgang De Meuter. In “Advanced Topics in Exception Handling Techniques”, C. Dony, J. L. Knudsen, A. Romanovsky, A. Tripathi (eds.), Lect. Not. Comp. Sc. 4119, pp. 141-160, Springer Verlag, 2006