Share via


ExceptionRoutedEventArgs 類別

定義

針對非同步作業引發為事件的例外狀況提供事件資料,例如 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
繼承
Object Platform::Object IInspectable RoutedEventArgs ExceptionRoutedEventArgs
衍生
屬性

範例

此範例示範在處理常式中使用 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)

適用於

另請參閱