ICoreApplicationUnhandledError.UnhandledErrorDetected Kejadian

Definisi

Terjadi ketika ada kesalahan dalam penangan penyelesaian asinkron, atau penanganan aktivitas, yang tidak ditangani oleh sistem atau kode aplikasi.

// 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) 

Jenis Acara

Keterangan

Kejadian ini dimunculkan setiap kali ada kesalahan dalam penyelesaian asinkron atau penanganan aktivitas yang mencapai bagian atas tumpukan tanpa ditangani oleh kode sistem atau aplikasi. Aplikasi Anda dapat memeriksa kesalahan dan memilih apakah akan menandai kesalahan sebagai ditangani (menggunakan properti Ditangani dalam data peristiwa). Jika kesalahan ditandai Ditangani, eksekusi akan berlanjut. Jika kesalahan tidak ditandai Ditangani, proses akan dihentikan.

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

Berlaku untuk

Lihat juga