locked
Deciphering HRESULT for network api failures

    Question

  • For failures when working with HTTPClient, the link http://msdn.microsoft.com/en-us/library/windows/apps/dn263240.aspx states to use the hresult of the exception passed.

    But to return the apt error to the dependent module for the network failure while using HTTPClient, I need to make sense of this hresult.

    The hresult being returned and the corresponding error enum is defined in wininet.h/inetmsg.h  but the same is not allowed to be used for windows metro app.

    What is the correct way then or the alternative to decipher the received hresult in an effort to - map the hresult to some defined enum to make sense out of it ??

    Tuesday, October 29, 2013 6:07 AM

Answers

All replies

  • Visual Studio 2012 or 2013 / Tools / Error Lookup
    Tuesday, October 29, 2013 6:12 AM
  • I meant -  handling the error programatically and returning this error further upstream to the dependent modules(and ultimately to the UI module) or as might the case be.
    Tuesday, October 29, 2013 6:24 AM
  • The choice of error-handling is largely up to you. WinRT APIs communicate errors as C++ exceptions. Many Win32 APIs use HRESULTS. You can pass errors however you want in your own code.

    Most of the Windows Store app DirectX samples make use of DX::ThrowIfFailed which just wraps the HRESULT into a Platform Exception.

    In general, you shouldn't try to 'handle' an error or exception you don't understand.

    Tuesday, October 29, 2013 6:29 AM
  • Chuck, Being explicit lets say for a scenario the exception thrown for SendRequestAsync() on HttpClient() has the HRESULT as 0x80072f06.

    Using the err tool we see the hresult corresponds to ERROR_INTERNET_SEC_CERT_CN_INVALID, defined in wininet.h.

    Do we have some header file available for metro apps where we have enums similar to above(ERROR_INTERNET_SEC_CERT_CN_INVALID) defined ?. This will help in meaningful way of passing around the error code to other dependent modules of ours. 



    • Edited by Aaaryaman Tuesday, October 29, 2013 9:16 AM minor correction
    Tuesday, October 29, 2013 6:38 AM
  • The Windows.Web.WebError.GetStatus(HRESULT)-->WebError static method is designed for this--it converts the HRESULT into a WebError which is a more convenient enum.

    Link:  http://msdn.microsoft.com/en-us/library/windows


    Network Developer Experience Team (Microsoft)

    Tuesday, October 29, 2013 6:01 PM