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

util.Try.apply catches control exceptions #5980

Closed
scabug opened this issue Jun 25, 2012 · 6 comments
Closed

util.Try.apply catches control exceptions #5980

scabug opened this issue Jun 25, 2012 · 6 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Jun 25, 2012

The source code for util.Try.apply has a catch block

  catch {
    case e => Failure(e)
  }

which will soak up control exceptions. Failure.recover and Success.flatMap have the same problem. The catch block should be

  catch {
    case ct: control.ControlThrowable => throw ct
    case e => Failure(e)
  }

If you try to use a return or a break from within these methods, this bug will result in a Failure instead of the desired control flow.

@scabug
Copy link
Author

scabug commented Jun 25, 2012

Imported From: https://issues.scala-lang.org/browse/SI-5980?orig=1
Reporter: @Ichoran
Affected Versions: 2.10.0-M4
See #2807

@scabug
Copy link
Author

scabug commented Jun 25, 2012

@retronym said (edited on Jun 25, 2012 9:59:23 PM UTC):
Arguably it shouldn't be catching {{Error}}-s, either.

@scabug
Copy link
Author

scabug commented Jul 6, 2012

@adriaanm said:
scala/scala#830

@scabug
Copy link
Author

scabug commented Aug 8, 2012

@Ichoran said:
The issue was only partly fixed: Success.flatMap is still (as of 2.10.M6 at least)

  def flatMap[U](f: T => Try[U]): Try[U] =
    try f(value)
    catch {
      case e: Throwable => Failure(e)
    }

which eats control exceptions.

@scabug
Copy link
Author

scabug commented Aug 9, 2012

@heathermiller said:
It is fixed though in the nightly. scala/scala#1056

@scabug scabug closed this as completed Aug 9, 2012
@scabug
Copy link
Author

scabug commented Aug 9, 2012

@scabug scabug added this to the 2.10.0 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants