I want to capture a divide by 0 exception and replace the value with another.

Here is the code I tried:
<code>
use v6;
my $d = 1;
my $e = 2;
my $f = 0;
#my $r;
my $r = 5;

CATCH {
# when X::AdHoc {
    when Exception {
    .Str.say;
# $r = 5;
     .resume
} }

$r = try {
    ( $d + $e ) / $f;
    };

# my $r = try EVAL ' ( 1 + 2 ) /0 ';

say "r is $r";
</code>

Suppose I wanted to trap an error in an EVAL statement?

I have tried reading the documentation on the perl6.org site, but I couldn't quite generalise it to the case I wanted.

I have tried a variety of things, but so far, I have worked out how to get this to work.

The documentation is also somewhat confusing about X::AdHoc and other exceptions. Is X::AdHoc the most general exception? Since this was not clear, I put 'Exception' in the CATCH block.

Regards,
Richard

Reply via email to