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

Применяется к

См. также раздел