Skip to content

Instantly share code, notes, and snippets.

@tsurushuu
Created September 25, 2011 04:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsurushuu/1240214 to your computer and use it in GitHub Desktop.
Save tsurushuu/1240214 to your computer and use it in GitHub Desktop.
readFile catch test.
import System.IO (hPutStrLn, stderr)
import Control.Exception (catch, IOException, SomeException)
import Prelude hiding (catch)
readFileWithDefault :: FilePath -> String -> IO String
readFileWithDefault filepath defaultString =
catch
(readFile filepath)
(\e -> do
return (e::SomeException)
-- hPutStrLn stderr $ "Warning: " ++ show (e:: SomeException)
return defaultString)
main :: IO ()
main = do
test <- readFileWithDefault "test.file" "CANT OPEN"
print test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment