Description
my.onError
Listen for mini program error event. Currently, only JS execution errors are supported. The trigger timing and parameters are the same as app.js registering Mini Program.
Input parameter
Function listener
Parameter
Property | Type | Compatibility | Description |
error | String | - | The description of the exception, which is generally the |
stack | String | Base database: 2.7.4 | The exception stack, which is generally the |
Sample code
my.onError(Function listener)
Page({
onLoad() {
my.onError(this.errorHandler);
},
errorHandler(error, stack) {
console.log('onError error', error);
console.log('onError stack', stack);
}
})If you use
my.onErrorto listen for errors,onErrormethods in theapp.jswill also listen for errors.Use
my.onErrorto listen for page errors. If listener is enabled on multiple pages and not closed, multiple listen events will be triggered when the page reports error. Therefore, it is recommended to callmy.offErrorto close the listener function when the page is closed.