-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
try-catch-else #21130
Comments
Yes, this seems like a good feature. |
Ref #1289 which is somewhat more confusing than |
I don't quite see the problem with try
maybe_raise_exception()
unrelated_stuff()
more_unrelated()
catch
stuff()
end There's no code duplication, and it seems like this is a normal way to use a Is the concern that you want to do something different if |
I think the issue is that |
What @yuyichao said. Additionally, I don't think that code that has no risk of throwing an exception should be in a |
See also #7026. The whole reason for try-catch-else is so that you don't accidentally catch an unexpected error thrown by |
I think this is a reasonable feature idea. I can see how it's somewhat redundant with the chain-of-custody design, but handles a much simpler and more limited case. It's not really necessary to be able to catch exceptions with fine granularity when all you need is to pop the exception handler for an easily-identified block of code. |
Sure, I was just closing due to lack of activity. Maybe we can see it in the future 🙂. |
Yes, there have definitely been cases where we implemented a feature literally years after it was requested. This one might not even take that long :-P |
I developed this for myself to get around some of the try/catch problems I encountered: |
There doesn't seem to be any real objection to this feature, someone just has to implement it. I've occasionally wanted this. |
I've removed the design and speculative labels since there doesn't seem to be much to design: allow an |
Coming from Python, I was really surprised to find that Julia has no way to execute code after a
try
block only if no exception/error was caught. Right now it seems the only way to get around this is something like:Whereas the Python code for this would read:
It seems like bad practice to put code that we aren't worried about causing exceptions/errors in a
try
block so I'm interested in hearing what others have to say about this.e: Alternatively you could do:
Although I do personally prefer the
else
syntax.The text was updated successfully, but these errors were encountered: