Boost logo

Boost :

From: Angus Leeming (angus.leeming_at_[hidden])
Date: 2005-09-28 08:47:00


Reece Dunn wrote:
> John Maddock wrote:
> > > It seems that testing for a path "J:/foo/bar" on a Win98 or Win2000
> > > machine (unsure which ATM) that doesn't have a J: drive is returning
> > > true falsely here because you ain't catching the correct error. Now,
> > > I have to say I
> > > don't agree with this policy of JM's, but suspect that the actual
> > > error is ERROR_INVALID_DRIVE. Will get back to you when my testers
> > > get back to me.
> >
> >I'm not sure I agree with that policy either: that's why there's a comment
> >in the code that it may not be correct. The basic problem is we don't know
> >which error codes represent "file does not exist", as opposed to some other
> >error. The fact there is no documentation on which error codes that API
> >can return makes the problem particularly tricky
>
> I agree that it could potentially return any error code, but according to
> the Windows documentation, the correct way of dealing with errors is to say:
>
> if( !SomeAPIThatMayFail( ... ))
> {
> DWORD error = GetLastError();
> // Process error based on values from winerror.h
> }

Sorry, John. That wasn't meant to be flaimbait :)

Hi, Reece. I've little knowledge of the "right way" here, but the code in
question does exactly what you suggest. It's just that it "plays God"
a little and decides that only some errors are real errors. If the error
isn't recognised then it tells the caller that all is well.

Given that my code is of the form

     if (exists(path) && is_directory(path)) ...

exists(path) returns true ATM causing is_directory(path) to throw_exception
when it can't find path. Given that I'm not using exceptions in this code,
I'd rather it lied conservatively rather than optimistically, if you get
what I mean...

The cure to my immediate problem is to have the actual error that my
user is experiencing added to the list of known errors. My intuition
tells me to expect ERROR_INVALID_DRIVE but I know we shouldn't write
code based on intuition :) I'll post back the actual error as and when
my bug reporter gets back to me with the results from a modified
version of the code. (I got it to throw_exception instead of return
true.)

It strikes me that a useful addition to the code here would be to get
the code to output a debug message indicating the (uncoded for but
probably valid) error code.

Regards,
Angus


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk