Catching A HRESULT?

This is a discussion on Catching A HRESULT? within the C++ Programming forums, part of the General Programming Boards category; I am having to use some old legacy code which throws HRESULTS. How do I catch these exceptions? What is ...

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    18

    Catching A HRESULT?

    I am having to use some old legacy code which throws HRESULTS. How do I catch these exceptions? What is the catch parameter for it?

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,413
    catch(HRESULT hr)
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Nov 2010
    Posts
    18
    Quote Originally Posted by Elysia View Post
    catch(HRESULT hr)
    Yes, that's the answer I was expecting but it's not catching it. I'm not really sure why.

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,413
    You should post the smallest possible compilable example that exhibits the problem, then.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Are you sure that they are throwing a HRESULT and not an exception like wrapper like _com_error or CAtlException?

  6. #6
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,288
    If it's using something like this:
    Code:
    HRESULT hr = E_FAIL;
    
    _com_issue_error(hr)
    then it is the kind of thing I use every day at work.
    You should catch it like this:
    Code:
    catch(const _com_error &e)
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  7. #7
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,147
    You may be having an issue related to threading or a non-local stack.

    Where is the exception being thrown from? Where are you trying to catch it?

    Soma

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Animated GIF Encoding Library
    By Tonto in forum C++ Programming
    Replies: 3
    Last Post: 01-08-2008, 12:57 PM
  2. LPCTSTR and HRESULT
    By George2 in forum C Programming
    Replies: 2
    Last Post: 07-27-2007, 02:17 AM
  3. Catching key strokes in a ListView
    By @nthony in forum Windows Programming
    Replies: 1
    Last Post: 07-28-2006, 02:40 AM
  4. Hresult
    By Unregistered in forum Windows Programming
    Replies: 1
    Last Post: 06-25-2002, 01:11 PM
  5. Catching bad input
    By Asmodan in forum C++ Programming
    Replies: 3
    Last Post: 05-28-2002, 06:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21