Hi Graeme,

Thanks for (another) fine report.  

It turns out that catching IOErrors _does_ work.  What doesn't work is the
tests "isDoesNotExistError", "isPermissionError", etc.

For reasons of portability, laziness (human), etc, Hugs doesn't make as fine
distinctions between different kinds of errors as the library report demands.
For example, readFile doesn't look to see whether "fopen" failed because
the file doesn't exist or because the file is unreadable.

Since Hugs doesn't distinguish the standard errors, testing for them will 
always return False.  Perhaps we should raise an error instead?

As a partial fix, I've added three new errors to the IO library.  The
"hugs" prefix is to make it clear that they are non-standard.

IO.hugsIsSearchErr :: IOError -> Bool
  -- approx: file/env variable does not exist
  -- raised by getEnv, readFile, readBinaryFile, writeFile (append mode),
IO.hugsIsNameErr   :: IOError -> Bool
  -- empty string used as argument (sort of a special case of search err)
  -- raised by system, openFile, readFile, readBinaryFile
IO.hugsIsWriteErr  :: IOError -> Bool
  -- cannot fopen a file 
  -- raised by writeFile

These will be in the next release.
In the meantime, you could implement these functions yourself by 
testing the value returned by IO.ioeGetErrorString :-(

Alastair

ps The library report is a little vague about which operations should report
   which errors and under what circumstances.  Apart from the Hugs problems,
   are you finding that other compilers are consistent with each other?

> 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