2006-10-19ずっと放置
■ [例外]undefinedやerrorを呼んだ時のExceptionはErrorCall?
undefinedやerrorで落ちそうなときもcatchできる。
ここで使う Control.Exception.catch の型は:
Control.Exception.catch :: IO a
-> (GHC.IOBase.Exception -> IO a)
-> IO a
Exception型
http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Exception.html#t%3AException
ErrorCallが投げられるっぽい。実際:
ghci> Control.Exception.catch (seq (error "error!!!") $ return ()) (\(Control.Exception.ErrorCall e)->putStrLn ("exception:"++show e))
exception:error!!!
ghci> Control.Exception.catch (seq undefined $ return ()) (\(Control.Exception.ErrorCall e)->putStrLn ("exception:"++e))
exception:Prelude.undefined
ghci> Control.Exception.catch (seq (head []) $ return ()) (\(Control.Exception.ErrorCall e)->putStrLn ("exception:"++e))
exception:Prelude.head: empty list
コメント