让我们做出以下假设:
我如何找出该例外的类型?
最小的例子:
main = error "foo"
(这是当然的ErrorCall,但你无法从错误信息中得知.)
Die*_*Epp 17
是.假设您使用新的异常API,所有Exception类型必须是实例Typeable.
import Control.Exception
import Data.Typeable
import Prelude hiding (catch)
realMain = error "example"
main = realMain `catch` h where
  h (SomeException e) = do
    putStrLn $ "Caught exception of type " ++ show (typeOf e)
    putStrLn $ show e
结果:
Caught exception of type GHC.Exception.ErrorCall example