Catching IO errors doesn't seem to work in Hugs 1.4 (Jan98):

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
import IO (isDoesNotExistError)

main :: IO ()
main = catch (readFile "wibble" >>= \s -> putStr s)
             (\e -> if isDoesNotExistError e
                    then putStr "File not found.\n"
                    else fail e)
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

when run with no file named "wibble" present produces:

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Main> main

File or variable not found: wibble
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

and:

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
import IO (isPermissionError)

main :: IO ()
main = catch (readFile "wibble" >>= \s -> putStr s)
             (\e -> if isPermissionError e
                    then putStr "Not allowed.\n"
                    else fail e)
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

when run with an unreadable file named "wibble" present also produces:

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Main> main

File or variable not found: wibble
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

hbc and ghc cope fine.

The alternative to catching is checking using the Directory 1.4
Library module but this does not appear to be present in Hugs 1.4?

Graeme.

Reply via email to