Promise.on.error

Description

Global exception handler for non-caught promises.

Deprecated Since Dexie 1.5.1. Obsolete since 2.0.0. Use onunhandledrejection instead

Subscibe

Dexie.Promise.on("error", myGlobalErrorHandler);

function myGlobalErrorHandler(error) {
    console.error(error);
    return false; // Returning false will prevent the default handler from being called.
}

Unsubscribe

Dexie.Promise.on("error").unsubscribe(myGlobalErrorHandler);

Parameters

error: AnyAny uncatched error no matter if it was a DB operation or any other non-db operation.

Remarks

This event will fire whenever a Dexie.Promise instance was rejected bug never caught. Returning false from your handler will prevent any earlier registered handler from being called. By default there is a handler that logs each unhandled promise to the console with console.warn(). Your handler will execute before the default handler. If you want to silence the default handler, return false from your handler.

Sample

Dexie.Promise.on("error", function (e) {
    var errorLabel = document.getElementByIf('errorLabel');
    if (errorLabel) {
        errorLabel.innerText = e.stack || e;
        return false;
    }
});

new Dexie.Promise(function () {
    throw "Oops!";
});

// promise not caught, so the error will bubble to Dexie.Promise.on('error').

Table of Contents