CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 7 of 7

Thread: ::CloseHandle throw an exception

Threaded View

  1. #1
    Join Date
    Dec 2005

    ::CloseHandle() throw an exception

    Hi Guys,

    Quote Originally Posted by msdn
    If the function succeeds, the return value is nonzero.

    If the function fails, the return value is zero. To get extended error information, call GetLastError.

    If the application is running under a debugger, the function will throw an exception if it receives either a handle value that is not valid or a pseudo-handle value. This can happen if you close a handle twice, or if you call CloseHandle on a handle returned by the FindFirstFile function instead of calling the FindClose function.
    I want to catch the exception but I couldn't find what type it is.
    I've tried:

    if ( m_hEvent != NULL && m_hEvent != INVALID_HANDLE_VALUE )
    	::CloseHandle(m_hEvent); // Call it again to trigger an exception
        catch (const std::exception &e)			
             AfxMessageBox(_T("This is an exception"));
        m_hEvent = NULL;
    It didn't catch it.
    Can anyone tell me what type of exception is thrown?
    Do I need to use try catch or checking the handle against null will be enough?

    Many thanks
    Last edited by Salvadoravi; December 12th, 2008 at 01:05 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)