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

try without catch not documented #9320

Closed
ArchRobison opened this issue Dec 11, 2014 · 13 comments
Closed

try without catch not documented #9320

ArchRobison opened this issue Dec 11, 2014 · 13 comments
Labels
docs This change adds or pertains to documentation

Comments

@ArchRobison
Copy link
Contributor

While reviewing #9316, I learned that try...end does not require a catch or finally. But I can't find this construct documented in the manual section about exception handling. Did I miss something, or do we need to describe it in the manual? The semantics are surprising for programmers coming from a C++ background, so I think it deserves notice.

The semantics seem to be that tryexprend returns the value of expr, unless an exception occurs, in which case it returns false.

@ivarne ivarne added the docs This change adds or pertains to documentation label Dec 11, 2014
@IainNZ
Copy link
Member

IainNZ commented Dec 12, 2014

Should probably return a Nullable

@JeffBezanson
Copy link
Member

Oops. I must have intended to return nothing, which is the standard value of an empty block like begin end or if false end.

@StefanKarpinski
Copy link
Member

I was going to say that nothing seems like the consistent thing to return here. I don't recall the timeline here but it's possible that you implemented try before we had nothing.

@kmsquire
Copy link
Member

The current behavior is used, e.g., in RandomMatrices.jl, to test for the ability to import another package.

Cc: @jiahao

@jiahao
Copy link
Member

jiahao commented Dec 12, 2014

@kmsquire I think the issue here is a little different. In my code I wrote HAVE_X = try using X; true catch false end which explicitly returns false when an exception is thrown. The specific behavior that is questionable is that try error() end == false, which is as if every try block had a default catch; return false clause.

@ArchRobison
Copy link
Contributor Author

Returning nothing seems much more coherent. The false had me puzzled.

@kmsquire
Copy link
Member

@jiahao, I read that code and don't know how I missed that! Sorry for the noise.

@MikeInnes
Copy link
Member

It occurs to me that we should add a way to document keywords like try via the repl help mode. I'll put this in when I get the chance.

@IainNZ
Copy link
Member

IainNZ commented Dec 14, 2014

It turns out a few packages relied on this behaviour, e.g. JSON:
https://github.com/JuliaLang/JSON.jl/blob/2fdfc2999593f287bea377b1604dd1302a75b12a/src/Parser.jl#L5-L8

@JeffBezanson
Copy link
Member

Yes, this should definitely not be backported since it is breaking.

jiahao added a commit to JuliaIO/JSON.jl that referenced this issue Dec 14, 2014
`try/catch` no longer returns `false` when no `catch` block is defined and an exception is thrown. Ref: JuliaLang/julia#9320
@kmsquire
Copy link
Member

I think I wrote that code, so that probably should have been my example
above. :-)

On Sunday, December 14, 2014, Jeff Bezanson [email protected]
wrote:

Yes, this should definitely not be backported since it is breaking.


Reply to this email directly or view it on GitHub
#9320 (comment).

@tkelman
Copy link
Contributor

tkelman commented Jan 6, 2015

Oh right, the behavior changed here. Still worth documenting 0.3's behavior on release-0.3. Would doing git diff 76c991d7~ 76c991d7 | sed -e 's/nothing/false/g' | git apply look okay to everyone?

jiahao added a commit that referenced this issue Jan 8, 2015
Closes #9320

(slightly modified backport of 76c991d,
try without catch returns `false` on release-0.3)
[ci skip]
@tkelman
Copy link
Contributor

tkelman commented Jan 8, 2015

There were no objections so I backported the modified version (returns false on release-0.3) in a1b156f

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

No branches or pull requests

9 participants