-
-
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
Deprecate error("msg")? #21886
Comments
I've wondered if |
In Common Lisp, it's accepted to use |
I remember seeing this proposed before, and after some digging I found the comment by @kmsquire #13515 (comment) |
|
You can, in fact, currently throw a string without wrapping it in an julia> typeof(try ; throw("asdf") ; catch ex ; ex end)
String The observation here is that this probably doesn't make a whole heap of sense, so we have the opportunity to turn two verbs into one by just removing error. It seems like a good pun to me. |
I don't think we should try to guess what the user want. We are in general moving away from |
Why? |
It offers no information of what actually happens. |
I'd be content to simply deprecate The argument that we should encourage users to throw more specific exception types holds more weight. |
No. Multiple dispatches should not be used that way. Multiple dispatch is generally used to select the best implementation and not completely changing the behavior. |
What do we gain by allowing users to throw things which are not subtypes of I agree that this is a change of behavior, and the deprecation would need to be handled correctly in stages. |
There is. Instead of giving an error you want it to do something that shouldn't be encouraged. |
So to recap, my own interpretation of the proposal is this:
In the last point, I see this as more-or-less "sugar" (it's not literally syntax sugar; we could use dispatch to arrange this) so that in the cases you want to be lazy, you can. Now, I do understand that it's much better practice to use the corresponding The consequences are that this "lispy" style of breaking through multiple stack frames by throwing whatever data type you want might not work as now. However, to make that safe, I think it would be better practice to make your own |
If people just want this, then we should keep |
And I only said I'm fine with deprecating The lisp usage of exception as control flow should not be as much of a concern in julia since we don't usually have as deep nesting AFAICT. |
+1. Base and serious packages should have properly typed exceptions, but for personal code, it would be annoying to specify which category each error fits into, because 99% of the time I have no intent of ever catching them, and the error message is all the information I want. |
Whether this is worse depends on your point of view. Throwing generic errors is more convenient and concise (good things), but less precise (arguably a bad thing). It's fine to discount convenience and concision as not worth the tradeoff here, but they are legitimate points in the design space, and julia is stylistically a very concise language. Furthermore, when exceptions are used to signal something very exceptional (programmer error) rather than to direct control flow, the detailed exception type is much less important: you probably shouldn't be directing flow control based on the type anyway. I feel this is a distinct departure from popular languages such as java, python, and C++, where flow control based on exception type is supported as part of the language, and is perfectly routine.
Yes, I hope we never start using exceptions for control flow 👍 |
Why not use |
This is quite a good point, I'd forgotten that it allowed arbitrary descriptive text. |
So what do people think of the following plan:
|
I didn't know |
@andyferris sounds like something that should be more prominent in the manual, then, if someone wants to open a PR... |
For me,
I see the merit in discouraging the use of |
So, we're almost back to the start of this discussion.
Does anyone have ideas about how to solve these, without loosing the concision of I suppose a survey of the way |
I use |
I think there are two related but separate issues here:
Concerning 2, I wonder how common a "log error and throw exception" pattern vs. a "throw an exception and log an error where it is caught" pattern would be. If the former is more common, it might even make sense to go the other way round and allow |
Thats basically what MATLAB does, i.e. |
@martinholters Hah! You've discovered my other (not so secret) motive :-) In that case I want to use
I've worked in code bases (in C++) using both of these patterns, and I far prefer the second one. The catch site is pretty much forced to log the error in either case because it doesn't know whether the thrower already did so. This results in double logging of errors all over the place which is somewhat annoying and confusing. |
I don't think
is possible because Maybe
with
will be nice but I don't think there is a general consensus for this... Maybe we could first deprecate use of
to
|
At this point, I think we can say we are post 1.0 and not going to introduce a breaking change to how these work unnecessarily. |
Deprecating isn't a breaking change (only is when you actually remove the API)?! So we can do that in 1.x, if this is helpful. I think it has a runtime cost, but that needs not be the case? Do we need soft-deprecations like Python? Can't we have such and deprecations that only point to alternative in the REPL, but in a script is no-coast (on default options)? |
I've just been in contact with a new user, who was understandably using
throw("my message")
rather than throwing anErrorException
viaerror()
.Do we need the conceptual overhead of having both
error
andthrow
? Why not conceptually have the following definitions:A somewhat related question - what do we gain by allowing people to throw things which aren't subtypes of
Exception
?The text was updated successfully, but these errors were encountered: