develooper Front page | perl.perl6.users | Postings from October 2018

Exception Handling, DivideByZero

Thread Next
Joseph Brenner
October 29, 2018 17:03
Exception Handling, DivideByZero
Message ID:
I was just looking into doing some finer-grained exception handling,
so I tried this:

   use v6;
   try {
       my $result = 4/0;
       say "result: $result";
       CATCH {
   #        when DivideByZero { say "Oh, you know."; }
           default { say .WHAT; .Str.say } # (DivideByZero)   Attempt
to divide 4 by zero using div

The first time through, The .WHAT tells me I've got
"DivideByZero", and so I added the line that's commented out
here, at which point I got the error:

   Function 'DivideByZero' needs parens to avoid gobbling block (or
perhaps it's a class that's not declared or available in this scope?)

Putting parens around (DivideByZero) doesn't help:

   Undeclared name:
      DivideByZero used at line 12

My impression was this would just work from looking
at the examples using things like X::AdHoc here:

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About