Created
March 8, 2021 21:13
-
-
Save codesections/df7ac67ba6e88ef907dd3095dc9b8641 to your computer and use it in GitHub Desktop.
Comparing `try` to a CATCH block in Raku
This file contains 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
my $result = do try { | |
# some code that may throw X::This | |
… | |
# some code that may throw X::NotSpecified (default) | |
… | |
# some code that may throw X::Something | |
… | |
# some code that may throw X::This or X::That | |
… | |
# some code that may fail instead of throw | |
# (sunk so that it will throw immediately) | |
sink may-fail; | |
} // do given { | |
when X::Something { … } | |
when X::This { … } | |
when X::That { … } | |
default { … } | |
} | |
#################### Instead of ####################### | |
my $result = do { | |
CATCH { | |
when X::Something { … } | |
when X::This { … } | |
when X::That { … } | |
default { … } | |
} | |
# some code that may throw X::This | |
… | |
# some code that may throw X::NotSpecified (default) | |
… | |
# some code that may throw X::Something | |
… | |
# some code that may throw X::This or X::That | |
… | |
# some code that may fail instead of throw | |
# (sunk so that it will throw immediately) | |
sink may-fail; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment