Drkcore

18 07 2012 Haskell Tweet

Haskellで例外を受け取る

IOの例外をキャッチしたくてはまった。

import System.Environment
import Control.Exception
import Prelude hiding (catch)
import System.Exit

main = do
  (file:_) <- getArgs
  catch (putStr =<< readFile file) $ \e -> return (e::SomeException) >> print ("Error on reading file: " ++ file)

-- main = do
--   (file:_) <- getArgs
--   catch (putStr =<< readFile file) $ \_ -> print ("Error on reading file: " ++ file)

例外の型を指定しないといけないらしい。

  • 第25回 Haskell流の例外処理を学ぶ

About

  • もう5年目(wishlistありマス♡)
  • 最近はPythonとDeepLearning
  • 日本酒自粛中
  • ドラムンベースからミニマルまで
  • ポケモンGOゆるめ

Tag

Python Deep Learning javascript chemoinformatics Emacs sake and more...

Ad

© kzfm 2003-2021