Add additional constructors for Try
object
#21545
tmccombs
started this conversation in
Feature Requests
Replies: 1 comment
-
https://www.scala-lang.org/files/archive/api/current/scala/util/control/Exception$.html
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Try.apply
currently returns aFailure
if aNonFatal
exception is thrown in the block.However, that often isn't what is actually desired.
In fact, in #17737 it was discussed that
NonFatal
should be deprecated, perhaps in favor of just catchingException
instead (in particular, see #17737 (comment)).It may also often be desirable to create a Try, but propagate
Break
exceptions, so that it can be used in a Boundary, for example in something like this:Currently, this would loop forever, since the Try would catch the
Break
exception. It would be nice if there was an easy to use method onTry
to create aTry
that lets throughBreak
exceptions, but catches other exceptions.Something like:
Some other possible types of conditions that may be useful to have additional methods for:
Although I'm not sure how useful those would be.
Some other related ideas
It would probably be valuable to have a
NonControl
matcher or maybeNonBreak
defined something like:I also wonder if it would be worth having a method on the
Try
trat like:Beta Was this translation helpful? Give feedback.
All reactions