Two issues:

(1) all standard exceptions are in or under the X:: namespace.

(2) .WHAT doesn't show names with their namespaces, whereas .^name does.

pyanfar Z$ 6 'my $r = 4/0; say $r; CATCH {default {say .^name}}'
X::Numeric::DivideByZero


On Mon, Oct 29, 2018 at 1:04 PM Joseph Brenner <doom...@gmail.com> wrote:

> 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
>


-- 
brandon s allbery kf8nh
allber...@gmail.com

Reply via email to