Say I do the following from ghci:
Prelude Control.Exception Data.Typeable> let a = read "A" :: Int
Prelude Control.Exception Data.Typeable> a
*** Exception: Prelude.read: no parse
Great! Now I just need to somehow know the type (and the module) of this exception to write an exception handler. Is there any way to get said type and module?
Built upon Daniel Wagner's answer:
import Control.Exception
import Data.Typeable
whichException :: IO a -> IO ()
whichException act = do
e <- try act
case e of
Left (SomeException ex) -> print $ typeOf ex
_ -> putStrLn "No exception occurred"
-- Usage:
-- > whichException (evaluate (read "A"::Int))
-- ErrorCall
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With