Share via


ICoreApplicationUnhandledError.UnhandledErrorDetected イベント

定義

非同期完了ハンドラーまたはイベント ハンドラーでエラーが発生し、それ以外の場合はシステムコードまたはアプリ コードによって処理されなかった場合に発生します。

// Register
event_token UnhandledErrorDetected(EventHandler<UnhandledErrorDetectedEventArgs> const& handler) const;

// Revoke with event_token
void UnhandledErrorDetected(event_token const* cookie) const;

// Revoke with event_revoker
ICoreApplicationUnhandledError::UnhandledErrorDetected_revoker UnhandledErrorDetected(auto_revoke_t, EventHandler<UnhandledErrorDetectedEventArgs> const& handler) const;
event System.EventHandler<UnhandledErrorDetectedEventArgs> UnhandledErrorDetected;
function onUnhandledErrorDetected(eventArgs) { /* Your code */ }
iCoreApplicationUnhandledError.addEventListener("unhandlederrordetected", onUnhandledErrorDetected);
iCoreApplicationUnhandledError.removeEventListener("unhandlederrordetected", onUnhandledErrorDetected);
- or -
iCoreApplicationUnhandledError.onunhandlederrordetected = onUnhandledErrorDetected;
Event UnhandledErrorDetected As EventHandler(Of UnhandledErrorDetectedEventArgs) 

イベントの種類

注釈

このイベントは、システムまたはアプリ コードで処理されずにスタックの最上位に達する非同期完了またはイベント ハンドラーにエラーが発生するたびに発生します。 アプリはエラーを検査し、エラーを処理済みとしてマークするかどうかを選択できます (イベント データの Handled プロパティを使用)。 エラーが [処理済み] とマークされている場合、実行は続行されます。 エラーが [処理済み] とマークされていない場合、プロセスは終了します。

Windows::ApplicationModel::Core::CoreApplication::UnhandledErrorDetected([](auto&&, auto&& args)
{
    if (!args.UnhandledError().Handled())
    {
        try
        {
            // Take the failure HRESULT and wrap it in a language specific exception.
            args.UnhandledError().Propagate();
        }
        catch (winrt::hresult_error const& e)
        {
            MyLogger::Log(e.message());
            // Since UnhandledError.Propagate marks the error as Handled, rethrow in order to only Log and not Handle.
            throw e;
        }
    }
});
CoreApplication::UnhandledErrorDetected += ref new EventHandler<UnhandledErrorDetectedEventArgs^ >(
    [](Platform::Object^ sender, UnhandledErrorDetectedEventArgs^ ea) ->
{
    if (!ea->UnhandledError->Handled)
    {
        try
        {
            // Take the failure HRESULT and wrap it in a language specific exception
            ea->UnhandledError->Propagate();
        }
        catch (Platform::Exception^ e)
        {
            MyLogger::Log(e->Message);
            // Since UnhandledError.Propagate marks the error as Handled, rethrow in order to only Log and not Handle
            throw e;
        }
    }
});

適用対象

こちらもご覧ください