Re: Exception handling

From: [at]} <Bob>
Date: Tue, 14 Sep 2004 20:48:13 +0100

----boundary-LibPST-iamunique-1647280113_-_-
Content-type: text/plain

Hi,

The ICL 2900 series of mainframes had a scripting language called SCL
based on Algol 68. There was a pre-defined result variable type which
you could pass by reference. Within each procedure you could declare one
WHENEVER clause which acted as an error-trap. For example:

PROC MYPROC( STRING S, REF RES RESULT ) IS
WHENEVER RES NE 0 DO
         --- try to recover, maybe ---
         EXIT
END

SOMEPROC( ..., RES )
(* if this goes wrong the WHENEVER will catch it *)

SOMEOTHERPROC( ..., RES )
IF RES NE 0 THEN (* override the WHENEVER *)
   THIRD( a, RES )
ELSE
    FOURTH( b, RES )
FI
...
END

(I don't remember the full details - it was a very long time ago)

So you could pass RES as a parameter to other called procedures, and
an explicit IF after the call would override the WHENEVER clause. It
was a very convenient way of handling 'errors' and I've always missed
it. It was a compromise between the daisy-chaining you can get from
nested IF res # OK THEN... after every call, and the nasty style of
exception handling in Java, C++ and that ilk.

Programming in SCL convinced me that it was unwise for the procedure
itself to decide that something is an error. Instead, it should always
pass a result code back up the line, and everything further up the
line should make up its own mind what to do about it - usually pass it
further up the line. The WHENEVER clause made that very easy because
you could just break right out.

The problem with the 'pure boolean' style that you describe is that it
is just that - boolean. With a result variable you can have shades of
grey.

Having said that, Z has a boolean way of handling errors that I rather
like. You need an schema to return OK in the event of successful
operation, called it OKSchema. Then you define the 'level-0' (my
terminology, not Z's) of the operation you're writing, eg

     Op0 := <boolean function>

3rd, define an error schema for your operation. Call it OpError. Then
extend it roughly as follows:

     Op := (Op0 AND OKSchema) OR OpError.

Both of these methods let you concentrate on the job of writing clear,
uncluttered code for the normal case, without obfuscating error code
getting in the way. But they let you write sensible error-handling
procedures as well.

-- 
Regards,
 Bob
Tuesday, September 14, 2004, 7:58:33 PM, you wrote:
> Gérard & René,
> If I might wade in a little on this discussion I have never found error
> handling by using a global routine useful simply because the definition
> of error is a function of the "context" in which it is found so no 
> global handler can correctly process it.  For example, if I fail to open
> an old file is that an error or is it a signal to the program that the
> file does not exist and hence one should branch to some other bit of code?
> I sometimes program in pure 'boolean' style where every procedure is
> either true or false.  A 'ladder' like sequence of 'if then else if ...'
> results.  Procedure P (which may be a test for zero) can then be used in
> various contexts where it may be considered a success or failure.
> -Doug
--------------------------------------------
To unsubscribe from this mailing list, send a message containing the word "unsubscribe" to:
   blackbox-request{([at]})nowhere.xyTo get a list of valid e-mail commands and instructions on their usage, send a message containing the word "help" to the above address.
Send any problem reports or questions related to this email list to the list owner at
   owner-blackbox{([at]})nowhere.xyCurrent posting policy:
a) To post you should use the same address by which you are subscribed to the mailing list. That way, the list server will recognize you as subscriber and forward your posting immediately, without creating any overhead.
b) If, for some reason, you cannot post from the address, by which you are subscribed, your message will be moderated to avoid spam. Please understand that moderation will often cause some delay, in particular over weekends or holydays.
----boundary-LibPST-iamunique-1647280113_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"
e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzc1xmY2hhcnNldDAgQXJpYWw7fQ0Ke1xmMVxmbW9kZXJuIENvdXJpZXIgTmV3O30NCntcZjJc
Zm5pbFxmY2hhcnNldDIgU3ltYm9sO30NCntcZjNcZm1vZGVyblxmY2hhcnNldDAgQ291cmllciBO
ZXc7fX0NCntcY29sb3J0YmxccmVkMFxncmVlbjBcYmx1ZTA7XHJlZDBcZ3JlZW4wXGJsdWUyNTU7
fQ0KXHVjMVxwYXJkXHBsYWluXGRlZnRhYjM2MCBcZjBcZnMyMCBIaSxccGFyDQpccGFyDQpUaGUg
SUNMIDI5MDAgc2VyaWVzIG9mIG1haW5mcmFtZXMgaGFkIGEgc2NyaXB0aW5nIGxhbmd1YWdlIGNh
bGxlZCBTQ0xccGFyDQpiYXNlZCBvbiBBbGdvbCA2OC4gVGhlcmUgd2FzIGEgcHJlLWRlZmluZWQg
cm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