ExceptionRoutedEventArgs ExceptionRoutedEventArgs ExceptionRoutedEventArgs Class

Provides event data for exceptions that are raised as events by asynchronous operations, such as ImageFailed.

Syntax

Declaration

public class ExceptionRoutedEventArgspublic class ExceptionRoutedEventArgsPublic Class ExceptionRoutedEventArgs

Inheritance Hierarchy

Inherited Members

Inherited properties

Remarks

Don't display ErrorMessage strings to end users. Instead, use substrings and codes within the string to positively identify the error condition, and have your app take appropriate action or display user-appropriate information in the app UI.

ExceptionRoutedEventArgs is the event data for several events that use the ExceptionRoutedEventHandler delegate. These include:

ExceptionRoutedEventArgs derived classes

ExceptionRoutedEventArgs is the parent class for MediaFailedRoutedEventArgs.

Examples

This example shows use of ExceptionRoutedEventArgs in a handler in order to get the HResult and error message.

private void videoMediaElement_MediaFailed(object sender, ExceptionRoutedEventArgs e)
{
    // get HRESULT from event args 
    string hr = GetHresultFromErrorMessage(e);

    // Handle media failed event appropriately 
}

private string GetHresultFromErrorMessage(ExceptionRoutedEventArgs e)
{
    String hr = String.Empty;
    String token = "HRESULT - ";
    const int hrLength = 10;     // eg "0xFFFFFFFF"

    int tokenPos = e.ErrorMessage.IndexOf(token, StringComparison.Ordinal);
    if (tokenPos != -1)
    {
        hr = e.ErrorMessage.Substring(tokenPos + token.Length, hrLength);
    }

    return hr;
}

Properties summary

Gets the message component of the exception, as a string.

Properties

  • ErrorMessage
    ErrorMessage
    ErrorMessage
    ErrorMessage

    Gets the message component of the exception, as a string.

    public string ErrorMessage { get; }public string ErrorMessage { get; }Public ReadOnly Property ErrorMessage As stringpublic string ErrorMessage { get; }

    Property Value

    • string
      string
      string

      The message component of the exception.

    Remarks

    Don't display ErrorMessage strings to end users. Instead, use substrings and codes within the string to positively identify the error condition, and have your app take appropriate action or display user-appropriate information in the app UI.

    Examples

    This example shows use of ExceptionRoutedEventArgs in a handler in order to get the HResult and error message. This is code that might support debugging and testing during development but wouldn't be found as-is in production code. Production code might take this example further though. For example, once you've isolated the HResult from the ErrorMessage, your app code could branch on the HResult values and provide notification to users of what went wrong and possible actions to take to correct the problem.

    private void videoMediaElement_MediaFailed(object sender, ExceptionRoutedEventArgs e)
    {
        // get HRESULT from event args 
        string hr = GetHresultFromErrorMessage(e);
    
        // Handle media failed event appropriately 
    }
    
    private string GetHresultFromErrorMessage(ExceptionRoutedEventArgs e)
    {
        String hr = String.Empty;
        String token = "HRESULT - ";
        const int hrLength = 10;     // eg "0xFFFFFFFF"
    
        int tokenPos = e.ErrorMessage.IndexOf(token, StringComparison.Ordinal);
        if (tokenPos != -1)
        {
            hr = e.ErrorMessage.Substring(tokenPos + token.Length, hrLength);
        }
    
        return hr;
    }
    

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.ComposableAttribute
Windows.Foundation.Metadata.ContractVersionAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute
Windows.Foundation.Metadata.ThreadingAttribute
Windows.Foundation.Metadata.WebHostHiddenAttribute

Details

Assembly

Windows.UI.Xaml.dll