Promise.onerror event

Occurs when there is an error in processing a promise.

The onerror event occurs whenever a runtime error is caught in any promise, whether or not it is handled elsewhere. You can use the error handler to set breakpoints while you're debugging or to provide general error handling such as error logging. But because this is a general error handling mechanism, you might not get much detail about the exact code or user input that caused the error.

For more information, see How to handle errors with promises.

Syntax

promise.addEventListener("error", listener);
//or 
promise.onerror = listener;

Event information

Synchronous No
Bubbles Yes
Cancelable Yes

 

Event handler parameters

  • eventInfo
    Type: CustomEvent**

    An object that contains information about the event.

Remarks

Here's how to add a general error handler:

function activatedHandler() {
    // add general activation code.
    WinJS.Promise.onerror = errorHandler;
}
function errorhandler(event) {
        // add general error handling, for example:
        var ex = event.detail.exception;
        var promise = event.detail.promise;
    }

Requirements

Minimum WinJS version

WinJS 1.0

Namespace

WinJS.Promise

See also

Promise