Skip to content

Instantly share code, notes, and snippets.

@Tarrasch
Created November 12, 2013 22:05
Show Gist options
  • Save Tarrasch/7439620 to your computer and use it in GitHub Desktop.
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
{-# 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