Created
November 12, 2013 22:05
-
-
Save Tarrasch/7439620 to your computer and use it in GitHub Desktop.
Haskell exception handling - Throwing a different exception from what you caught inside the handler
This file contains hidden or 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
{-# LANGUAGE DeriveDataTypeable #-} | |
module InsideNew where | |
import Control.Exception | |
import Data.Typeable | |
data MyException = MyException | |
deriving (Show, Typeable) | |
instance Exception MyException | |
insideNew :: IO Int | |
insideNew = catch dangerousAction handler | |
where | |
dangerousAction :: IO Int | |
dangerousAction = error "We're gonna crash" | |
handler :: SomeException -> IO Int | |
handler e = -- A catch-all handler | |
if 1 == 2 | |
then do putStrLn "Handled!" | |
return 200 | |
else do putStrLn "Have to propagate :/" | |
throw newException -- Throw along a different exception, not e! | |
newException = MyException -- Whatever here really |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment