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

test_throws message confuses me #9686

Closed
matrixmorpheus opened this issue Jan 9, 2015 · 4 comments
Closed

test_throws message confuses me #9686

matrixmorpheus opened this issue Jan 9, 2015 · 4 comments
Labels
domain:error handling Handling of exceptions by Julia or the user status:help wanted Indicates that a maintainer wants help on an issue or pull request

Comments

@matrixmorpheus
Copy link
Contributor

There’s nothing I can say that will explain it for you. See for yourself.

julia> @test_throws DomainError throw(DomainError)
ERROR: test failed: DomainError was thrown instead of DomainError
in expression: throw(DomainError)
in error at error.jl:21
in default_handler at test.jl:27
in do_test_throws at test.jl:69

@ihnorton ihnorton added the domain:error handling Handling of exceptions by Julia or the user label Jan 9, 2015
@ihnorton
Copy link
Member

ihnorton commented Jan 9, 2015

The issue is that run_test_throws checks isa not is -- it only checks whether the thrown error is an instance of the given type, but not the type itself. This works:

@test_throws DomainError throw(DomainError())

It's an easy change, but I'm not really sure if there might be some other implication.

@ivarne
Copy link
Sponsor Member

ivarne commented Jan 10, 2015

That message is really confusing. It should be pretty simple to check is when isa is false and instruct the caller to throw an instance instead of a type.

@StefanKarpinski is it considered valid to throw a type?

@ivarne ivarne added the status:help wanted Indicates that a maintainer wants help on an issue or pull request label Jan 10, 2015
@JeffBezanson
Copy link
Sponsor Member

Julia makes it too easy to define

error{E<:Exception}(::Type{E}) = throw(E())

and so in some places the idiom error(DomainError) is used. I've never liked this however.

@ivarne
Copy link
Sponsor Member

ivarne commented Jan 11, 2015

See also #9690

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:error handling Handling of exceptions by Julia or the user status:help wanted Indicates that a maintainer wants help on an issue or pull request
Projects
None yet
Development

No branches or pull requests

4 participants