At 09:29 AM 8/16/00 -0500, Jonathan Scott Duff wrote:
>Let me draw another picture (with "try" and "catch" this time):
>
>         try {
>             # code that may cause exceptions
>         } catch {                       # catches ALL exceptions
>             switch ($@->^_) {
>                 case canFoo             { ... ; undef $@ }
>                 case isa('IOError')     { ... ; undef $@ }
>                 case isa('Oops')        { ... ; undef $@ }
>             }
>         }                               # implicit throw here if defined $@
>
>To signal that the exception was handled, the programmer undefs $@.
>That way if the user wishes to do something when an exception occurs,
>but not handle it, they just don't undef $@.

Well, this is the most credible proposal for using switch that I've yet 
seen; but it forces the user to type the same piece of arcana into 
practically every catch block.  I want the commonest case to be the 
simplest and most readable, and 99% of every exception handling thing I've 
written has gone something like (adjusting to new syntax):

         try {
                 blah;   # usually tens of lines of code
         } catch Exception::This {
                 blech;  # handle Exception::This
         } catch Exception::That {
                 plugh;  # handle Exception::That
         } catch {
                 xyzzy;  # handle other exceptions (omitted 1/4 the time)
         } finally {
                 foo;    # Even this block only appears 1/2 the time or less
         }


>BTW, I hope you guys don't find me frustrating,

Heck no, this is how it's supposed to work.

>  I'm just trying to
>decide what exception handling should look like in Perl to me.

--
Peter Scott
Pacific Systems Design Technologies

Reply via email to