Changes between Initial Version and Version 1 of R6RSExceptionHandlingCowan


Ignore:
Timestamp:
11/15/10 20:22:45 (7 years ago)
Author:
cowan
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • R6RSExceptionHandlingCowan

    v1 v1  
     1== Exceptions == 
     2 
     3This is a proposal for basic exception-handling and exception-raising constructs. 
     4 
     5The exception system allows the program, when it detects an exceptional situation, to pass control to an ''exception handler'', and to dynamically establish such exception handlers. Exception handlers are one-argument procedures that determine the action the program takes when an exceptional situation is signalled.  Exception handlers are always invoked with an object (which may be of any type) describing the exceptional situation.  The system implicitly maintains a ''current exception handler''.  
     6 
     7The program raises an exception by invoking the current exception handler, passing it an object encapsulating information about the exception. Any procedure accepting one argument may serve as an exception handler and any object (called a ''condition object'') may be used to represent an exception. 
     8 
     9The system maintains the current exception handler as part of the dynamic environment of the program. 
     10 
     11When a program begins its execution, the current exception handler is expected to handle all exceptions by interrupting execution, reporting that an exception has been raised, and displaying information about the condition object that was provided. The handler may then exit, or may provide a choice of other options.  Interpretation of these expectations necessarily depends upon the nature of the system in which programs are executed, but the intent is that users perceive the raising of an exception as a controlled escape from the situation that raised the exception, not as a crash. 
     12 
     13== Procedures and syntax forms == 
     14 
     15`(with-exception-handler `''handler''` `''thunk''`)` 
     16 
     17''Handler'' must be a procedure and should accept one argument. ''Thunk'' must be a procedure that accepts zero arguments. The `with-exception-handler` procedure returns the results of invoking ''thunk''. ''Handler'' is installed as the current exception handler for the dynamic extent (as determined by `dynamic-wind`) of the invocation of ''thunk''. 
     18 
     19Implementation responsibilities: The implementation must check the restrictions on handler to the extent performed by applying it as described when it is called as a result of a call to `raise` or `raise-continuable`. An implementation may check whether ''handler'' is an appropriate argument before applying it. 
     20 
     21`(guard (`''variable''` . `''cond clauses''`) `''body''`)` 
     22 
     23Syntax: Each ''cond clause'' is as in the specification of `cond`. 
     24 
     25Semantics: Evaluating a guard form evaluates ''body'' with an exception handler that binds the raised object to ''variable'' and within the scope of that binding evaluates the clauses as if they were the clauses of a `cond` expression. That implicit `cond` expression is evaluated with the continuation and dynamic environment of the guard expression. 
     26 
     27If the test of every ''cond clause'' evaluates to `#f` and there is no `else` clause, then `raise` is re-invoked on the raised object within the dynamic environment of the original call to `raise`, except that the current exception handler is that of the guard expression. 
     28 
     29The final expression in a ''cond clause'' is in a tail context if the `guard` expression itself is. 
     30 
     31`(raise `''obj''`)` 
     32 
     33Invokes the current exception handler on ''obj''.  The handler is called with a continuation whose dynamic environment is that of the call to `raise`, except that the current exception handler is the one that was in place when the handler being called was installed. If the handler returns, an exception is raised non-continuably in the same dynamic environment as the handler. 
     34 
     35`(raise-continuable `''obj''`)` 
     36 
     37Invokes the current exception handler on ''obj''.  The handler is called with a continuation that is equivalent to the continuation of the call to `raise-continuable`, with these two exceptions:  
     38 
     39 1) the current exception handler is the one that was in place when the handler being called was installed,  
     40 
     41 2) if the handler being called returns, then it will again become the current exception handler. If the handler returns, the values it returns become the values returned by the call to `raise-continuable`. 
     42 
     43== Error procedures == 
     44 
     45`(error `''message-string''` . `''irritants''`)` 
     46 
     47Constructs an ''error condition'' and raises it as if using `raise`.  The error condition may be of any Scheme type; the ''message-string'' and ''irritants'' must be retrievable from it.  The ''message-string'' is intended to be a human-readable report of the error.  This is SRFI 23 `error`. 
     48 
     49`(error-in `''source''` `''message-string''` . `''irritants''`)` 
     50 
     51Constructs an ''error condition'' and raises it as if using `raise`.  The error condition may be of any Scheme type; the ''source'', ''message-string'' and ''irritants'' must be retrievable from it.  The ''source'' is a string or symbol describing the procedure or operation that detected the error; the ''message-string'' is intended to be a human-readable report of the error.  This is R6RS `error`. 
     52 
     53`(error-message `''obj''`)` 
     54 
     55Returns the message-string from ''obj'' if ''obj'' is an error condition, and `#f` otherwise. 
     56 
     57`(error-irritants `''obj''`)` 
     58 
     59Returns the irritants from ''obj'' if ''obj'' is an error condition, and `#f` otherwise. 
     60 
     61`(error-source `''obj''`)` 
     62 
     63Returns the source from ''obj'' if ''obj'' is an error condition, and `#f` otherwise. 
     64 
     65