import System.IO
main :: IO ()
-main = do ignoreExceptions $ removeFile to
+main = do tryIO $ removeFile to
cs_before <- getDirectoryContents "copyFile"
putStrLn "Before:"
print $ sort cs_before
print $ sort cs_before
readFile to >>= print
+tryIO :: IO a -> IO (Either IOException a)
+tryIO = try
+
from, to :: FilePath
from = "copyFile/source"
to = "copyFile/target"
main = do d <- getCurrentDirectory
flip finally (setCurrentDirectory d) $ do
setCurrentDirectory "copyFile"
- ignoreExceptions $ removeFile to
+ tryIO $ removeFile to
cs_before <- getDirectoryContents "."
putStrLn "Before:"
print $ sort cs_before
print $ sort cs_before
readFile to >>= print
+tryIO :: IO a -> IO (Either IOException a)
+tryIO = try
+
from, to :: FilePath
from = "source"
to = "target"
-Left CreateDirectory: already exists (Cannot create a file when that file already exists.)
+Left createDirectory001.dir: createDirectory: already exists (File exists)
--- /dev/null
+Left CreateDirectory: already exists (Cannot create a file when that file already exists.)