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 methods returning Try may throw exceptions instead of returning Failure #6333

Closed
scabug opened this issue Sep 6, 2012 · 2 comments
Closed
Assignees
Milestone

Comments

@scabug
Copy link

@scabug scabug commented Sep 6, 2012

The following code should throw no exceptions e.g. when pasted into the REPL. The solution in each case is the same: to wrap the call to the offending function or by-name parameter in the standard try/catch block.

import util.Try

val a = "apple"
def fail: String = throw new Exception("Fail!")
def argh: Try[String] = throw new Exception("Argh!")

// None of these should throw anything
Try(fail).orElse(argh)                                  // In Try
Try(a).transform(_ => argh, _ => argh)                  // In Try
Try(fail).transform(_ => argh, _ => argh)               // In Try
Try(fail).recoverWith{ case e if (a==fail) => Try(a) }  // In Failure
Try(fail).recoverWith{ case _ => argh }                 // In failure
@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Sep 6, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6333?orig=1
Reporter: @Ichoran
Affected Versions: 2.10.0-M7
Other Milestones: 2.10.0

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Sep 7, 2012

@scabug scabug closed this Sep 11, 2012
@scabug scabug added this to the 2.10.0-M7 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.