Last active
April 4, 2023 16:24
-
-
Save lucs/31159810c43a0c18e5265d38b10f9120 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is more like what I was trying to do. | |
try { | |
CATCH { | |
# We don't care about this error, and we want to continue. | |
when X::Str::Numeric { | |
.resume; | |
} | |
default { | |
put "But when an unknown exception happens for example, we want to rethrow it."; | |
put "Here, it's a ", .^name, " exception that occured."; | |
.rethrow; | |
} | |
} | |
put +"asdf"; | |
put 42 / 0; | |
put "Won't be printed."; | |
} | |
put "Won't be printed either, because the division by 0 will rethrow."; | |
=finish | |
Outputs: | |
(HANDLED) Cannot convert string to number: base-10 number must begin with valid digits or '.' in '⏏asdf' (indicated by ⏏) | |
in block <unit> at /tmp/snips-raku/e05.raku line 17 | |
But when an unknown exception happens for example, we want to rethrow it. | |
Here, it's a X::Numeric::DivideByZero exception that occured. | |
Attempt to divide by zero when coercing Rational to Str | |
in block <unit> at /tmp/snips-raku/e05.raku line 18 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment