-
-
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
Give better messages in DomainError where possible. #2144
Comments
Cc: @alanedelman |
sqrt(-1) is the highest priority of them all |
In cases where there is "no method" why can't we also printout the possible Methods? |
That's a good idea. Or at least we can say "try methods(f) to see all available methods for f", especially in cases where there are a lot of methods (e.g. +). |
I was thinking about raising this issue in #4187, but then I reliezed that someone might have tought about it before, and did a search. A possibility might be to add a new exception |
We could also just print an error message with domain errors and not create a new type of error. |
Wouldn't a printed message be annoying if I try to evaluate a function (that calls
Is there any philosophical reason that |
I don't really see why you'd want to do that and this hasn't been a problem with sqrt so far. The alternative is to have a real and complex version of every single function – the way that Matlab has The current arrangement uses function composition instead: whenever
No – in fact I suspect that all errors should contain a helpful error message. I'm not entirely sure why we have so many exception types with no messages. @JeffBezanson? |
I totally agree with your first paragraph. Sorry that the example code ended up so big compared to the comment. The example was to show why one might want to catch a DomainError silently. |
Why not just have an optional string associated with |
Adding a message might be ok. The only advantage to having no message is it ensures nothing needs to be allocated to throw the exception. Otherwise the code to allocate and initialize the object has to be inlined everywhere sqrt is used. |
The thing that I've been missing in error messages is the values of arguments that caused the error – if we can get both the error location and arguments from the stack trace then adding a message is largely unnecessary. |
Sorry for commenting before understanding how things work and how similar problems have been solved earlier, and what is actually beeing discussed. Am I right if the discussion is about how ´showerror(io::IO, e::DomainError)´ should be implemented? For me adding
to repl.jl would be very nice.
This might be what @StefanKarpinski suggested when he said "We could also just print an error message with domain errors and not create a new type of error." If this is acceptable I would be delighted to submit a PR. |
Unfortunately DomainError is used for errors that can not be fixed with complex(x), so this will be wrong. Adding a subtype |
Why not just add |
Mostly for backwards compatibility. It is also a pluss to group similar
|
@HomerReid really liked the error for diag(a::Vector), where it suggests that perhaps the user should use
diagm
. He was wondering if we can do so in many other cases, to ease the learning curve for new julia users.In the case of
DomainError
and other cases, we may be able to offer a helpful suggestion in the same way. A common example issqrt(-1)
.The text was updated successfully, but these errors were encountered: