my.onUnhandledRejection

Listen for the unhandledrejection event. The unhandledrejection event is triggered when a JavaScript Promise that has no rejection handler is rejected. The triggered time of the callback for the unhandledrejection event and required parameters are the same with those of the onUnhandledRejection() method.

Sample code

copy
//.js
App({
  onShow(options) {
    my.onUnhandledRejection((res) => {
      console.log(res.reason);
      console.log(res.promise);
    });
  }
})

Parameters

PropertyTypeDescription
callbackFunction

The unhandledrejection event is triggered when a JavaScript Promise that has no rejection handler is rejected.

Callback function

PropertyTypeDescription

reason

String

Rejection reason, which usually is the error object.

promise

Promise

The rejected Promise object.