Catch exceptions in an Iteratee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Exception (Exception, catch) | |
import Data.Enumerator (Iteratee (..), Step (..)) | |
import Data.ByteString (ByteString) | |
import Prelude hiding (catch) | |
catchIter :: Exception e | |
=> Iteratee ByteString IO a | |
-> (e -> Iteratee ByteString IO a) | |
-> Iteratee ByteString IO a | |
catchIter (Iteratee mstep) f = Iteratee $ do | |
step <- mstep `catch` (runIteratee . f) | |
return $ case step of | |
Continue k -> Continue $ \s -> catchIter (k s) f | |
Yield b s -> Yield b s | |
Error e -> Error e |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Not works for errors such
divide by zero
e.t.c. In this case flow not reach line 15.UPD: Sorry. Only for lazy functions.