Task: Catch Throwable, not just Exception #608

Merged
merged 1 commit into from Jan 3, 2014

Conversation

Projects
None yet
4 participants
@jessitron
Contributor

jessitron commented Dec 17, 2013

Task.Try catches Exception, but not Throwable.
The consequence is that when trampolining, if a Throwable pops up then the thread dies and the program never terminates.

It's a good rule of thumb to never catch Throwable, but this is an exception. If the intention of "Don't catch Throwable" is "Let the program die", then it is more useful to wrap the Throwable, give it back to the other thread, and throw it again there.
As it is, the contents of the Throwable are lost in the aether of the dying thread, never to be diagnosed.

Paul says: it should catch all Throwables, that is a bug. It's up to the consumer of Task to rethrow any non-Exception Throwables if that's the behavior they want.

from discussion:
https://groups.google.com/forum/#!topic/scalaz/D3ZyY1Xu_PQ

@S11001001

This comment has been minimized.

Show comment
Hide comment
@S11001001

S11001001 Jan 3, 2014

Member

Looks good. @pchiusano ?

Member

S11001001 commented Jan 3, 2014

Looks good. @pchiusano ?

@pchiusano

This comment has been minimized.

Show comment
Hide comment
@pchiusano

pchiusano Jan 3, 2014

Member

Looks good, merging now. Sorry I missed this, need to subscribe to PR notifications on scalaz repo.

Member

pchiusano commented Jan 3, 2014

Looks good, merging now. Sorry I missed this, need to subscribe to PR notifications on scalaz repo.

pchiusano added a commit that referenced this pull request Jan 3, 2014

Merge pull request #608 from jessitron/TaskCatchingThrowable
Task: Catch Throwable, not just Exception

@pchiusano pchiusano merged commit 4b8b2d7 into scalaz:scalaz-seven Jan 3, 2014

1 check passed

default The Travis CI build passed
Details
@kevinmeredith

This comment has been minimized.

Show comment
Hide comment
@kevinmeredith

kevinmeredith Apr 7, 2017

Contributor

Naive question, is it a good or bad idea to, upon pattern matching on a java.lang.Throwable that's not a scala.util.control.NonFatal, automatically shut down the JVM?

Example (taken from this PR):

 def Try[A](a: => A): Throwable \/ A =
   try \/-(a) catch { 
          case scala.util.control.NonFatal(e) => -\/(e)
          case e        => System.exit(-1)
   }

Please note that I'm not suggesting this behavior, but asking in order to learn.

Thanks!

Contributor

kevinmeredith commented Apr 7, 2017

Naive question, is it a good or bad idea to, upon pattern matching on a java.lang.Throwable that's not a scala.util.control.NonFatal, automatically shut down the JVM?

Example (taken from this PR):

 def Try[A](a: => A): Throwable \/ A =
   try \/-(a) catch { 
          case scala.util.control.NonFatal(e) => -\/(e)
          case e        => System.exit(-1)
   }

Please note that I'm not suggesting this behavior, but asking in order to learn.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment