From: Goran on
On Feb 23, 7:25 pm, "Tom Serface" <t...(a)camaswood.com> wrote:
> Hi Joe,
>
> I suspect you are right in this case, but I've found it useful to protect
> file based operations with exception handling code since it doesn't really
> slow it down much and some of the SDK functions will throw exceptions in
> exceptional conditions.

Wait, what? Are there some SDK file functions that could throw an SE?
(I am concerned because Windows would be horrible if e.g. ReadFile,
WriteFile, CreateFile could throw __anything__ under any condition!)

Goran.

P.S. Please tell me it ain't so!
From: Joseph M. Newcomer on
CloseHandle definitely will, code 0xC0000008 or 0xC0000009 (I forget which), if you try to
close an invalid handle.

AFAIK, ReadFile, WriteFile and CreateFile can throw exceptions only if you pass an invalid
address into them.
joe

On Wed, 24 Feb 2010 00:54:39 -0800 (PST), Goran <goran.pusic(a)gmail.com> wrote:

>On Feb 23, 7:25�pm, "Tom Serface" <t...(a)camaswood.com> wrote:
>> Hi Joe,
>>
>> I suspect you are right in this case, but I've found it useful to protect
>> file based operations with exception handling code since it doesn't really
>> slow it down much and some of the SDK functions will throw exceptions in
>> exceptional conditions.
>
>Wait, what? Are there some SDK file functions that could throw an SE?
>(I am concerned because Windows would be horrible if e.g. ReadFile,
>WriteFile, CreateFile could throw __anything__ under any condition!)
>
>Goran.
>
>P.S. Please tell me it ain't so!
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Giovanni Dicanio on
"Joseph M. Newcomer" <newcomer(a)flounder.com> ha scritto nel messaggio
news:dcnao51dc7afjl92u7lrc8qgd1utuvrq39(a)4ax.com...

> CloseHandle definitely will, code 0xC0000008 or 0xC0000009 (I forget
> which), if you try to
> close an invalid handle.

I used to think that CloseHandle can't throw an exception (it could return
an error code, but not throw an exception).

This seems to confirm that:

http://blogs.msdn.com/oldnewthing/archive/2008/01/07/7011066.aspx

Giovanni



From: Joseph M. Newcomer on
Not sure what that article confirms. Even in Vista, and back in NT4, I got this behavior.
Try this simple program:

int _tmain(int argc, _TCHAR* argv[])
{
HANDLE h = ::CreateEvent(NULL, FALSE, FALSE, NULL);
::CloseHandle(h);
// The call below gives the exception
// First-chance exception at 0x77a45e4f in CloseHandle.exe: 0xC0000008: An invalid
handle was specified.
::CloseHandle(h);
return 0;
}

I ran it in Vista a few minutes ago and the error text you see is a copy-paste from the
MessageBox.
joe

On Wed, 24 Feb 2010 20:28:08 +0100, "Giovanni Dicanio"
<giovanniDOTdicanio(a)REMOVEMEgmail.com> wrote:

>"Joseph M. Newcomer" <newcomer(a)flounder.com> ha scritto nel messaggio
>news:dcnao51dc7afjl92u7lrc8qgd1utuvrq39(a)4ax.com...
>
>> CloseHandle definitely will, code 0xC0000008 or 0xC0000009 (I forget
>> which), if you try to
>> close an invalid handle.
>
>I used to think that CloseHandle can't throw an exception (it could return
>an error code, but not throw an exception).
>
>This seems to confirm that:
>
>http://blogs.msdn.com/oldnewthing/archive/2008/01/07/7011066.aspx
>
>Giovanni
>
>
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: David Lowndes on
>Not sure what that article confirms. Even in Vista, and back in NT4, I got this behavior.
>Try this simple program:
>
>int _tmain(int argc, _TCHAR* argv[])
>{
> HANDLE h = ::CreateEvent(NULL, FALSE, FALSE, NULL);
> ::CloseHandle(h);
> // The call below gives the exception
> // First-chance exception at 0x77a45e4f in CloseHandle.exe: 0xC0000008: An invalid
>handle was specified.
> ::CloseHandle(h);
> return 0;
>}
>
>I ran it in Vista a few minutes ago and the error text you see is a copy-paste from the
>MessageBox.

Isn't that just something you get running under the debugger though?

Modify the code - put a MessageBox after the second CloseHandle, and
run it outside the debugger.

Dave