Skip to content
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

Clarification on try/catch/finally blocks and a few more examples #10776

Closed
wants to merge 2 commits into from

Conversation

harikb
Copy link
Contributor

@harikb harikb commented Apr 9, 2015

I have a few edits for the try/catch/finally blocks. Related discussion on this topic in julia-users mailing is here https://groups.google.com/d/msg/julia-users/Kqn6gNIwD5o/g9xiMmOKAoIJ

I understand this is a fairly extensive edit than what is discussed in the thread, but I think it clarifies a lot of things. If you want me to remove any edits, please let me know and I will undo them and resubmit.

All examples are quoted from real julia session. I have done "make html" and verified it appears ok. However, I have not been successful running doctest in general (even before this change) because of the issue mentioned in this post https://groups.google.com/d/msg/julia-users/n0OjsGJpMRc/XOdv7Uqtu9oJ

@harikb
Copy link
Contributor Author

harikb commented Apr 9, 2015

Thanks, I didn't know what. That said, although I removed that phrase from the original example, the return value of nothing is documented below (in a separate section on return values, after the finally is explained, with many examples). I have tried to use nothing (in quotes), but let me see if I can word it better. I removed it from original example to clearly state that "return value of nothing" is caused by the empty block and not something special about that terse syntax. Unless it is something special about catch clause. I know nothing about Julia internals, buy my explanation based on reading rest of the manual sounded intuitive to me.

julia> nothing == try end
true

julia> nothing == begin end
true

I will resubmit tomorrow.

Thanks for your time

@harikb
Copy link
Contributor Author

harikb commented Apr 9, 2015

elextr, I am still purplexed by this comment

note the value nothing can be tested so you can tell if the block exited by exception rather than returning its last expression

julia> nothing == try println("hello") end
hello
true

If developers start using return of nothing to detect having got an exception, that is bad as well. In the above example, there is perfectly valid non-erroring block and it returns nothing (because println returns nothing)

IMHO, we should be simply saying 'it returns the last expression executed' (just like any other block) - that is how I have worded it.

@elextr
Copy link

elextr commented Apr 10, 2015

Of course if the normal return from the block is also nothing then you can't tell if there was an exception, but then you probably don't use the value of the try block if its normal value is nothing.

If there is an exception the value of the try block is nothing and that must be documented correctly, saying that the value is the last expression is wrong if there is an exception.

You are not meant to use the nothing to detect exceptions to do something with them, thats what catch is for.

But if you are ignoring exceptions and the normal value of the try block is something else and you use that value then you probably need to check, because further computations using that value may barf with nothing. It would be nice to mention this.

@kshyatt kshyatt added the docs This change adds or pertains to documentation label Jul 2, 2015
@harikb harikb closed this Sep 21, 2015
@tkelman
Copy link
Contributor

tkelman commented Sep 22, 2015

@harikb sorry we seem to have lost track of this. It looks like your commit 1526a54 still applies and would be a useful doc addition?

@harikb
Copy link
Contributor Author

harikb commented Oct 3, 2015

thanks. I closed only because I thought I couldn't state my point with elextr. I didn't know Julia enough to continue to make the case, so I left it.

@harikb harikb reopened this Oct 3, 2015
@elextr
Copy link

elextr commented Oct 3, 2015

@harikb I'm not sure what is still open, you have documented the fact that the try code end construct returns nothing on an exception. That was all I was after.

@vtjnash
Copy link
Member

vtjnash commented Jun 26, 2019

Since this PR, we renamed the file (from rst to md format). Is it something we should revive?

@harikb harikb closed this Mar 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This change adds or pertains to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants