ExceptionRoutedEventArgs 類別

定義

提供非同步作業引發為事件之例外狀況的事件資料,例如 ImageFailed

public ref class ExceptionRoutedEventArgs : RoutedEventArgs
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 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(Windows.Foundation.UniversalApiContract), 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
繼承
Object Platform::Object IInspectable RoutedEventArgs ExceptionRoutedEventArgs
衍生
屬性

Windows 需求

裝置系列
Windows 10 (已於 10.0.10240.0 引進)
API contract
Windows.Foundation.UniversalApiContract (已於 v1.0 引進)

範例

此範例示範如何在處理常式中使用 ExceptionRoutedEventArgs,以取得 HResult 和錯誤訊息。

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;
}

備註

不要向使用者顯示 ErrorMessage 字串。 請改用字串內的子字串和程式碼,以正面識別錯誤狀況,並讓您的應用程式採取適當的動作,或在應用程式 UI 中顯示使用者適當的資訊。

ExceptionRoutedEventArgs 是使用 ExceptionRoutedEventHandler 委派之數個事件的事件資料。 其中包括:

ExceptionRoutedEventArgs 衍生類別

ExceptionRoutedEventArgs 是 MediaFailedRoutedEventArgs的父類別。

屬性

ErrorMessage

取得例外狀況的訊息元件,做為字串。

OriginalSource

取得引發事件之 物件的參考。 這通常是控制項的範本部分,而不是在應用程式 UI 中宣告的專案。

(繼承來源 RoutedEventArgs)

適用於

另請參閱