locked
C++/CX - How do you get the exception message from a thrown exception?

    Question

  • Source: http://PasswordMgr.CodePlex.com change set: 102031

    I'm performing TDD against a composite base class and want to send a comprehensive message if the developer fails to register an IBaseClass implementation.  Below (figure 1) I throw the message and I get an unexpected response (figure 2).

    In the top pane of image below I have my unit test (which currently fails as expected).  It fails because I don't register implementation for a required dependency (IBaseClass) and on line 15 I attempt to Resolve<TestWoof>(container).

    In the middle pane of image below I have my mock TestWoof class.  Its OnContainerSet() will use the container to pull the composite base class implementation and in this case fail.  I throw a comprehensive message, but where I can see it in the watch window and output window (bottom pane of image below) I have no public properties to access it.  Is there a way? 


    Figure 3


    MCAD.NET C# - http://www.Global-webnet.com/Blog


    • Edited by BillKrat1 Sunday, March 10, 2013 10:43 PM minor updates for clarity
    Sunday, March 10, 2013 10:41 PM

Answers

  • I found a solution to the problem.  I basically had to create a exception framework around a user defined HResult. 

    I blog on the entire process, with source code, HERE


    MCAD.NET C# - http://www.Global-webnet.com/Blog

    • Marked as answer by BillKrat1 Monday, March 11, 2013 4:59 AM
    Monday, March 11, 2013 4:59 AM

All replies

  • You can use the FormatMessage function to look up descriptions of error codes.

    --Rob

    Monday, March 11, 2013 12:14 AM
    Owner
  • It became quickly apparent that the following flag was not supported (red underline in VS 2012) - so I remarked it out and tried variations of the provided samples, as well as comments to the samples, and none of them had successful results - each sample resulted in different errors and lacked support, e.g., LocalFree().

    In digging deeper into the available documentation I discovered the following sentence that suggest that "as-is" we can use it for debug purposes (see highlighted below) - which is consistent with my results.  I'll have to explore the "user-defined" HResult.


    MCAD.NET C# - http://www.Global-webnet.com/Blog

    Monday, March 11, 2013 2:20 AM
  • I found a solution to the problem.  I basically had to create a exception framework around a user defined HResult. 

    I blog on the entire process, with source code, HERE


    MCAD.NET C# - http://www.Global-webnet.com/Blog

    • Marked as answer by BillKrat1 Monday, March 11, 2013 4:59 AM
    Monday, March 11, 2013 4:59 AM
  • MSFT should just support transfering the String you can give PlatformException over to the calling app with "Windows Blue". After all its just a HSTRING so marshalling is not a problem.
    Tuesday, March 26, 2013 12:51 PM