[Haskell-cafe] Using catch and errors
Alexandre Weffort Thenorio
alethenorio at home.se
Fri Apr 22 10:40:45 EDT 2005
I am trying to get catch to work but I guess I am total newbie on this one.
main :: IO()
main = do
removeFile "./newint.hex"
hexFile <- catch (readFile int.hex) (\_ -> do putStrLn "Cannot find
int.hex"
getLine --Simply stop program so user can read error message
return() --Quit)
hexFile <- readFile "int.hex"
--res of program goes here
getLine
return()
But it keeps giving me error on getLine. How can I quit a program in case of
an error giving an error message?
Also I tried something like
main :: IO()
main = do
ex <- doesFileExist "./newint.hex"
if ex then removeFile "./newint.hex"
But that won't work either. Any ideas? I'd like to catch different errors
and quit program giving different error messages
Last but not least I have the function
outputLine keyno key orgFile = do
let part1 = getLeft keyno (orgFile!!1)
let part2 = getRight keyno (orgFile!!1)
let total = part1 ++ (map toUpper key) ++ part2
let checks = checksum (drop 1 total)
let final = total ++ checks ++ "\n"
newHexFile <- openFile "newint.hex" WriteMode
hPutStrLn newHexFile (orgFile!!0 ++ "\n" ++ final ++ unlines (drop 2
orgFile))
I'd like to be able to check for stuff such as size of key and wheter keyno
is only 1 or 0 and quit program with error message otherwise but again
couldn't quite get catch to work.
Any reading tips about subject would be appreciated.
Best Regards
NooK
More information about the Haskell-Cafe
mailing list