Skip to content


IO.except not working correctly #56

purefn opened this Issue · 3 comments

1 participant

putStrLn("first!") >|> throwIO(new Exception("help!")) except (e => putStrLn(e.getMessage)) unsafePerformIO

results in the output

java.lang.Exception: help!
at $anonfun$1.apply(<console>:17)
at $anonfun$1.apply(<console>:17)
at scalaz.MA$$anonfun$$greater$great

instead of the expected


This occurs on master.


It appears as though except is only catching exceptions that occur in the first piece of IO. So

throwIO[Unit](new Exception("help!")) >|> putStrLn("first!") except (e => putStrLn(e.getMessage)) unsafePerformIO

works as expected.


I've found a solution, but I'm not sure it's the best solution. If we define except as

def except(handler: Throwable => IO[A]): IO[A] =
  IO(rw => try { val (nw, a) = this(rw).run; return_((nw, a)) } catch { case e => handler(e)(rw) })

The above cases work. I tried just using reset to do the same, but it winds up being too lazy. So we have to force the strictness in this case.

Does this look correct? If so I'll push the fix to master and scalaz-seven.

@purefn purefn closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.