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

Exception Handling, DivideByZero

Thread Next
From:
Joseph Brenner
Date:
October 29, 2018 17:03
Subject:
Exception Handling, DivideByZero
Message ID:
CAFfgvXXb-k4RC7UpBRR5y0xSvDVggLM6i3-5fVu_R1s+-VQPBg@mail.gmail.com
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:

   ===SORRY!===
   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:

  https://docs.perl6.org/language/exceptions

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About