my.onUnhandledRejection().
Parameters
Code Example
Remove Specific Listener
Remove All Listeners
Page Lifecycle Management
Related APIs
my.onUnhandledRejection
Listen for unhandled rejections
my.offError
Stop listening for error events
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Stop listening for unhandled Promise rejection events.
my.onUnhandledRejection().
| Property | Type | Required | Description |
|---|---|---|---|
| callback | Function | No | The specific callback to remove. If omitted, all listeners are removed. |
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 unhandled rejection listeners
my.offUnhandledRejection();
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);
}
});
my.offUnhandledRejection() that was used with my.onUnhandledRejection() to remove only that specific listener.