locked
[C++]MediaCapture.InitializeAsync error not caught in try block RRS feed

  • Question

  • I have the InitializeAsync in a try/catch block, but if there is an error, it is not caught.  It seems to go to a pplawait getresults and fails.  I am using a co_await, I guess this will not work with a try-catch??

    try
    	{
    		co_await mediaCapture->InitializeAsync(captureInitSettings);
    	}
    
    	catch (Exception^ e)
    	{
    		NotifyUser("Video/Audio: " + e->Message, NotifyType::ErrorMessage);
    		m_startupFailTimer = 10;
    		return;
    	}


    Martin Autry


    • Edited by Breeze Liu Wednesday, October 25, 2017 7:52 AM [C++]
    Friday, October 20, 2017 10:27 PM

Answers

  • I will check that.  I found a way around the problem by using the create_task and putting the try on the get.  That seemed to work.

    Martin Autry

    • Marked as answer by dannyfarwin Thursday, October 26, 2017 2:52 AM
    Thursday, October 26, 2017 2:52 AM

All replies

  • Hi dannyfarwin,

    Do you mean it comes to break but not be caught by the method catch(Exception^ e) when your code has an error in the block of try? If so, you can try to change the Exception settings. On the menu bar, choose Debug->Windows->ExceptionSettings, you can see the Exception setting window and try to change the settings in c++ Exceptions.

    Best regards,
    Breeze

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Edited by Breeze Liu Monday, October 23, 2017 11:33 AM
    Monday, October 23, 2017 11:29 AM
  • Hi dannyfarwin,

    My first thought is that co_await is wrapping the exception in a data structure other than Exception^. If this is the case you should be able to figure out what data structure is being used by doing a "catch all".

    For example:

    try

    {
        // ...
    }

    catch (...)

    {
        // ...
    }

    I hope this helps,

    James


    Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Wednesday, October 25, 2017 8:25 PM
  • I will check that.  I found a way around the problem by using the create_task and putting the try on the get.  That seemed to work.

    Martin Autry

    • Marked as answer by dannyfarwin Thursday, October 26, 2017 2:52 AM
    Thursday, October 26, 2017 2:52 AM
  • That sounds like a legitimate approach too. I would still be curious to see what happens if you try to catch all. If you get a chance to test this please let use know.

    -James


    Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

    Thursday, October 26, 2017 6:06 PM