An exceptional exception

I've been doing some testing to try to figure out the tangled maze that is exception handling. (Is there a *reason* why half of all exceptions are dynamic, and the other half aren't? Couldn't we have just 1 system?) Anyway, I wrote a cute little "test" function for figuring out how each kind of exception works:
test (fail "go away") isAlreadyExistsError=False isDoesNotExistError=False isAlreadyInUseError=False isFullError=False isEOFError=False isIllegalOperation=False isPermissionError=False isUserError=True
Next I tried this:
test (getDirectoryContents "banana") isAlreadyExistsError=False isDoesNotExistError=True isAlreadyInUseError=False isFullError=False isEOFError=False isIllegalOperation=False isPermissionError=False isUserError=False
And now, this:
test (writeFile "C:\\C:\\x" "test") isAlreadyExistsError=False isDoesNotExistError=False isAlreadyInUseError=False isFullError=False isEOFError=False isIllegalOperation=False isPermissionError=False isUserError=False
Erm... so this exception registers as "False" on every single predicate? How exactly am I meant to detect this error?

2007/11/8, Andrew Coppin
Anyway, I wrote a cute little "test" function for figuring out how each kind of exception works:
Hi, could you post your code for this "cute" test? I would be greatful. Thanks, Radek P.S. Not that I can help, but I'd like to start learning this. -- Codeside: http://codeside.org/ Przedszkole Miejskie nr 86 w Lodzi: http://www.pm86.pl/

Radosław Grzanka wrote:
2007/11/8, Andrew Coppin
: Anyway, I wrote a cute little "test" function for figuring out how each kind of exception works:
Hi, could you post your code for this "cute" test? I would be greatful.
Thanks, Radek
P.S. Not that I can help, but I'd like to start learning this.
For you (and anybody else who's interested), it can be found here: http://www.hpaste.org/3766 ;-)

Well, my problems have now multiplied beyong belief! Allow me to summerise: 1. There exists an I/O exception called "invalid parameter", which is not detectable with any of the 8 predicates. (Isn't this what "illegal operation" is supposed to be for? A general catch-all?) 2. Attempting to open an invalid filename yields the undetectable "invalid parameter" exception (rather than, say, illegal operation). 3. Attempting to read a directory with an invalid name does the same. 3. Attempting to open a *file* you don't have permission for yields "permission error", as expected. However, attempting to read a *directory* yields... invalid parameter again. (Thus, even if this exception were detectable, there's no way to tell the difference between a permission error and a malformed filename.) 4. Not actually related to exceptions, but doesDirectoryExist "C:\" yields False. (Even though getDirectoryContents "C:\" yields the correct result.) So I can't even use that to filter out invalid directory names. Aaaarrrgh! >_< Clearly, making my program give the user meaningful error messages is going to be very hard - unless I resort to trying to *parse* the output of the Show instance for IOError... Does anybody have any helpful hints for me at this point?

On Nov 9, 2007, at 15:01 , Andrew Coppin wrote:
4. Not actually related to exceptions, but doesDirectoryExist "C:\" yields False. (Even though getDirectoryContents "C:\" yields the correct result.) So I can't even use that to filter out invalid directory names.
This is an ancient and extremely annoying general DOS/Windows wart. The root directory has several unexpected behaviors, because it is *not* in fact a directory (or wasn't on FAT, and the behaviors have to be kept for backward compatibility). (You're also not the only one to be frustrated by having to parse stringified I/O exceptions to decipher them.) -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH
participants (3)
-
Andrew Coppin
-
Brandon S. Allbery KF8NH
-
Radosław Grzanka