[comp.lang.ada] Optional Sequence of Statements Before Exception Handlers

edm@vrdxhq.verdix.com (Ed Matthews) (06/29/90)

I've been thinking about the following situation recently:

  exception
    when foo_error =>
      A;
      B;
    when bar_error =>
      A;
      B;
      C;
    when others =>
      A;
      B;
      D;
  end;

and wondering if allowing the following would be a "good thing:"

  exception
    A;
    B;  -- these two statements comprise the optional sequence before handlers
    when foo_error =>
      null;
    when bar_error =>
      C;
    when others =>
      D;
  end;

This obviously poses some awkward spots -- like the null; statement with
non-null semantics and if an exception occurs in the optional sequence
of statement, where/how/in which scope it can be handled.  

Of course, we can always write a procedure encapsulating A; B; and call it
from each of the handlers.  Then we get into the wouldn't it be nice if
we could pass parameters to handlers and access the name of the exception
(or an enumeration literal representing the exception) in a standard manner.

Anybody know what the current thinking about exception handling is with
respect to 9X?
-- 

Ed Matthews                                                edm@verdix.com
Verdix Corporation Headquarters                            (703) 378-7600
Chantilly, Virginia

pattis@cs.washington.edu (Richard Pattis) (07/01/90)

In article <34741@vrdxhq.verdix.com>, edm@vrdxhq.verdix.com (Ed Matthews) writes:
> I've been thinking about the following situation recently:
> 
>   exception
>     when foo_error =>
>       A;
>       B;
>     when bar_error =>
>       A;
>       B;
>       C;
>     when others =>
>       A;
>       B;
>       D;
>   end;
> 
> and wondering if allowing the following would be a "good thing:"
> 
>   exception
>     A;
>     B;  -- these two statements comprise the optional sequence before handlers
>     when foo_error =>
>       null;
>     when bar_error =>
>       C;
>     when others =>
>       D;
>   end;
> 

How about:


EXCEPTION
  WHEN OTHERS =>
      A;
      B;
      BEGIN
        RAISE;
      EXCEPTION
         WHEN foo_error => NULL;
         WHEN bar_error => C;
         WHEN others    => D;
      END;
      -- Can put post statements here (done for all exceptions)
END;

Rich Pattis

PS: Actually, I've never programmed this, but I have thought about it; if it
won't work, I'm sure some kind soul will tell me so, loudly.

daniel@mizar.docs.uu.se (Daniel Wengelin) (07/03/90)

In article <12427@june.cs.washington.edu>, pattis@cs.washington.edu
(Richard Pattis) writes:
 EXCEPTION
   WHEN OTHERS =>
       A;
       B;
       BEGIN
         RAISE;
       EXCEPTION
          WHEN foo_error => NULL;
          WHEN bar_error => C;
          WHEN others    => D;
       END;
       -- Can put post statements here (done for all exceptions)
 END;
 PS: Actually, I've never programmed this, but I have thought about it; if it
 won't work, I'm sure some kind soul will tell me so, loudly.

The code above was tested on a Sun3/60 using Telesofts TELEGEN2 SunAda 1.4.
It works just fine !

Daniel Wengelin.