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/catch catches NonLocalReturnException #2807
Comments
Imported From: https://issues.scala-lang.org/browse/SI-2807?orig=1 |
@paulp said: I want to make case e => or case _ => ... compile time errors. If you really want to catch Throwable (which you basically never should) you would have to say case e: Throwable. However before I would push for that I really need to get scala.util.control.Exception into a more finished state. By the way I put a warning in to complain about these a while ago. % scala -Ywarn-catches
scala> // your code here
<console>:14: warning: catch clause swallows everything: not advised.
case e => {
^ |
@hubertp said: |
Rob Ennals (robennals) said: -Rob |
@ijuma said: I'd suggest changing: class NonLocalReturnException[T](val key: AnyRef, val value: T) extends RuntimeException with ControlException to class NonLocalReturnException[T](val key: AnyRef, val value: T) extends ControlException That would be an improvement over the current situation. |
@paulp said: Martin said he's take it under advisement but naturally he resists because it introduces non-orthogonality between regular pattern matches and catches. |
@retronym said: try x catch { case _ => } |
@dragos said: |
@adriaanm said: |
@retronym said: |
@adriaanm said: |
something in this area could be revived on https://contributors.scala-lang.org |
Currently if I write some code like this:
Then the catch statement ends up catching the value returned by the return statement.
This is deeply confusing...
Would there be a possible workaround for this? E.g. could we declare that, by default, a pattern for an exception does not match NonLocalReturnException?
It would at least be nice to have some prominent documentation warning users about this problem.
The text was updated successfully, but these errors were encountered: