sub div($a, $b) {
my $r;
try {
$r = $a / $b;
CATCH {
default { note "Unexpected exception, $_" }
}
}
return $r // Nil;
}
say div(10,2);
say div(1, sin(0));
5
Unexpected exception, Attempt to divide 1 by zero using /
Nil
multi div($a, $b) { return $a / $b }
multi div($a, $b where { $b == 0 }) { note 'Attempt to divide by zero.'; return Nil }
say div(10, 2);
say div(1, sin(0));
5
Attempt to divide by zero.
Nil