From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fac41,f66d11aeda114c52 X-Google-Attributes: gidfac41,public X-Google-Thread: 103376,f66d11aeda114c52 X-Google-Attributes: gid103376,public From: mw@ipx2.rz.uni-mannheim.de (Marc Wachowitz) Subject: Re: Building blocks (Was: Design By Contract) Date: 1997/09/09 Message-ID: <5v3b61$r77$1@trumpet.uni-mannheim.de>#1/1 X-Deja-AN: 272591522 Organization: --- Newsgroups: comp.lang.ada,comp.lang.eiffel Date: 1997-09-09T00:00:00+00:00 List-Id: mheaney@ni.net (Matthew Heaney) wrote: > I've always been curious about the semantics of exception propagation, > because it doesn't correspond to anything in pure math (or does it?). If I > divide x by 0 on paper, I can strug my shoulders and say, "Oh well, > division by 0 isn't defined," but on a computer, I have to do _something_. That's easy. All functions (or generally procedures, or any statements and expressions) can be seen as mappings from one state to another, and among the possible outcomes of a such functions are the "normal outcome", where no exception was raised, and some "abnormal outcome" (possibly indicating the detailed cause for the exception as well, whether just with a name, or with additional data, like the error code of some system call). In the area of applicative languages, and the associated theory, there's even something known as continuation-passing style, where any sequence of computation is made explicit by passing to every function another function, the so-called continuation, which is invoked with the result of the former function. Then control structure manifests as a choice between many possible continuations. You could model the dynamic nesting of exception handlers by passing to each function (in the general sense; i.e. also expressions/statements) both a continuation for normal cases and a continuation for exceptional cases, and functions without any own exception handlers would pass along whatever they received as their exception-continuation. When an exception handler doesn't propagate the exception, that means that it invokes the appropriate normal continuation of its own context. In Scheme (a Lisp dialect), continuations are even available to programmers and can be used to model a variety of other control structures, including exceptions, but also backtracking or coroutines. (For detailed background, I suggest you ask on comp.lang.scheme about these things; there are people who can probably give you better references to books or papers on the net than the little I'd have available.) -- Marc Wachowitz