Skip to main content
Use this API to stop listening for unhandled Promise rejection events that were registered with my.onUnhandledRejection().

Parameters

PropertyTypeRequiredDescription
callbackFunctionNoThe specific callback to remove. If omitted, all listeners are removed.

Code Example

Remove Specific Listener

App({
  onLaunch() {
    my.onUnhandledRejection(this.rejectionHandler);
  },

  rejectionHandler(res) {
    console.error('Unhandled rejection:', res.reason);
  },

  // Call this to remove the listener
  removeRejectionListener() {
    my.offUnhandledRejection(this.rejectionHandler);
  }
});

Remove All Listeners

// Remove all unhandled rejection listeners
my.offUnhandledRejection();

Page Lifecycle Management

Page({
  onShow() {
    my.onUnhandledRejection(this.handleRejection);
  },

  onHide() {
    // Clean up when page is hidden
    my.offUnhandledRejection(this.handleRejection);
  },

  handleRejection(res) {
    console.error('Rejection on page:', res.reason);
  }
});
Pass the same callback function reference to my.offUnhandledRejection() that was used with my.onUnhandledRejection() to remove only that specific listener.

my.onUnhandledRejection

Listen for unhandled rejections

my.offError

Stop listening for error events