Re: Exception handling

From: [at]} <Bob>
Date: Wed, 15 Sep 2004 19:20:55 +0100

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

Hi Rene,

> Maybe I did not understand what you were saying, but I think of two
> ways currently used by the BB to do such a thing:

> 1. If you have a procedure, make it a "function", returning an integer
> as a return code. That way, the caller may decide how to react to a
> "grey" error.
> 2. Where you already return something valueable, have a VAR-parameter
> with the return code. If you must not complete your action due to the
> nature of the error, fill the variable, and then RETURN.

With an SCL-style WHENEVER clause you can turn something like this:

PROCEDURE P( ..., VAR res : INTEGER );
BEGIN
     P0(..., res );
     IF res = OK THEN
        P1(..., res );
        IF res = OK THEN
           P2( ..., res );
           IF res = OK THEN
              .
              .
              .
           END
        END
     END
END P;

into this:

PROCEDURE P( ..., VAR res: RESULT );
BEGIN
    WHENEVER res # OK DO
       some sort of recovery, or error message or whatever
       EXIT (* optional - you could continue with the procedure *)
    END;
    
    P0(..., res );
    P1(..., res );
    P2(..., res );
    .
    .
    .
END P;

with a function you could write:

PROCEDURE P( ... ): RESULT;
VAR res: RESULT;
BEGIN
     WHENEVER res # OK DO
        whatever
        RETURN res;
     END
   ...
   RETURN OK;
END P;

It is syntactic sugar, of course, but it can be very convenient and a
great aid to clarity. It also eliminates the daisy-chaining you can get
whether you use a RETURN or a VAR.

I've googled around a bit for some examples. They're quite hard to
find, but here's a page full of them:
http://www.mfleming.tele2.co.uk/vme/scl/

and here's one of them which gives a good flavour of it:
http://www.mfleming.tele2.co.uk/vme/scl/getcorr.txt

I always found it a very enjoyable and productive language to use.
When I first started using PCs I looked around for a language that was
similar. Somebody recommended Pascal or Modula-2, so I bought JPI Modula-2.
That was my introduction to the www (wonderful world of Wirth).

-- 
Regards,
 Bob
--------------------------------------------
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-1500525102_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"
e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzcyBBcmlhbDt9DQp7XGYxXGZtb2Rlcm4gQ291cmllciBOZXc7fQ0Ke1xmMlxmbmlsXGZjaGFy
c2V0MiBTeW1ib2w7fQ0Ke1xmM1xmbW9kZXJuXGZjaGFyc2V0MCBDb3VyaWVyIE5ldzt9fQ0Ke1xj
b2xvcnRibFxyZWQwXGdyZWVuMFxibHVlMDtccmVkMFxncmVlbjBcYmx1ZTI1NTt9DQpcdWMxXHBh
cmRccGxhaW5cZGVmdGFiMzYwIFxmMFxmczIwIEhpIFJlbmUsXHBhcg0KXHBhcg0KPiBNYXliZSBJ
IGRpZCAgbm90IHVuZGVyc3RhbmQgd2hhdCB5b3Ugd2VyZSBzYXlpbmcsIGJ1dCBJIHRoaW5rIG9m
IHR3b1xwYXINCj4gd2F5cyBjdXJyZW50bHkgdXNlZCBieSB0aGUgQkIgdG8gZG8gc3VjaCBhIHRo
aW5nOlxwYXINClxwYXINCj4gMS4gSWYgeW91IGhhdmUgYSBwcm9jZWR1cmUsIG1ha2UgaXQgYSAi
ZnVuY3Rpb24iLCByZXR1cm5pbmcgYW4gaW50ZWdlclxwYXINCj4gYXMgYSByZXR1cm4gY29kZS4g
VGhhdCB3YXksIHRoZSBjYWxsZXIgbWF5IGRlY2lkZSBob3cgdG8gcmVhY3QgdG8gYSBccGFyDQo+
ICJncmV5IiBlcnJvci5ccGFyDQo+IDIuIFdoZXJlIHlvdSBhbHJlYW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Bj
b250YWluaW5nIHRoZSB3b3JkICJoZWxwIiB0byB0aGUgYWJvdmUgYWRkcmVzcy5ccGFyDQpccGFy
DQpTZW5kIGFueSBwcm9ibGVtIHJlcG9ydHMgb3IgcXVlc3Rpb25zIHJlbGF0ZWQgdG8gdGhpcyBl
bWFpbCBsaXN0IHRvIHRoZSBsaXN0IG93bmVyIGF0XHBhcg0KICAgb3duZXItYmxhY2tib3hAb2Jl
cm9uLmNoXHBhcg0KXHBhcg0KQ3VycmVudCBwb3N0aW5nIHBvbGljeTpccGFyDQpccGFyDQphKSBU
byBwb3N0IHlvdSBzaG91bGQgdXNlIHRoZSBzYW1lIGFkZHJlc3MgYnkgd2hpY2ggeW91IGFyZSBz
dWJzY3JpYmVkIHRvIHRoZSBtYWlsaW5nIGxpc3QuIFRoYXQgd2F5LCB0aGUgbGlzdCBzZXJ2ZXIg
d2lsbCByZWNvZ25pemUgeW91IGFzIHN1YnNjcmliZXIgYW5kIGZvcndhcmQgeW91ciBwb3N0aW5n
IGltbWVkaWF0ZWx5LCB3aXRob3V0IGNyZWF0aW5nIGFueSBvdmVyaGVhZC5ccGFyDQpccGFyDQpi
KSBJZiwgZm9yIHNvbWUgcmVhc29uLCB5b3UgY2Fubm90IHBvc3QgZnJvbSB0aGUgYWRkcmVzcywg
Ynkgd2hpY2ggeW91IGFyZSBzdWJzY3JpYmVkLCB5b3VyIG1lc3NhZ2Ugd2lsbCBiZSBtb2RlcmF0
ZWQgdG8gYXZvaWQgc3BhbS4gUGxlYXNlIHVuZGVyc3RhbmQgdGhhdCBtb2RlcmF0aW9uIHdpbGwg
b2Z0ZW4gY2F1c2Ugc29tZSBkZWxheSwgaW4gcGFydGljdWxhciBvdmVyIHdlZWtlbmRzIG9yIGhv
bHlkYXlzfX0ALDAGBP8=
----boundary-LibPST-iamunique-1500525102_-_---
Received on Wed Sep 15 2004 - 20:20:55 UTC

This archive was generated by hypermail 2.3.0 : Thu Sep 26 2013 - 06:28:36 UTC