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

適用於

另請參閱