ExceptionRoutedEventArgs Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Provides event data for exceptions that are raised as events by asynchronous operations, such as ImageFailed.
public ref class ExceptionRoutedEventArgs : RoutedEventArgs
/// [Windows.Foundation.Metadata.ContractVersion(Microsoft.UI.Xaml.WinUIContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class ExceptionRoutedEventArgs : RoutedEventArgs
[Windows.Foundation.Metadata.ContractVersion(typeof(Microsoft.UI.Xaml.WinUIContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public class ExceptionRoutedEventArgs : RoutedEventArgs
Public Class ExceptionRoutedEventArgs
Inherits RoutedEventArgs
- Inheritance
- Derived
- Attributes
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;
}
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:
- Image.ImageFailed
- ImageBrush.ImageFailed
- BitmapImage.ImageFailed
- Windows.UI.Xaml.Controls.MediaElement.MediaFailed (for this event you can cast the event data to the more specific MediaFailedRoutedEventArgs result).
ExceptionRoutedEventArgs derived classes
ExceptionRoutedEventArgs is the parent class for MediaFailedRoutedEventArgs.
Properties
ErrorMessage |
Gets the message component of the exception, as a string. |
OriginalSource |
Gets a reference to the object that raised the event. This is often a template part of a control rather than an element that was declared in your app UI. (Inherited from RoutedEventArgs) |