Description
my.onError
Listens for Mini Program error events. Currently, only JavaScript execution errors are supported. The trigger timing and parameters are the same as onError(error: String).
Input parameter
Function listener
Parameter
|
Attribute |
Type |
Compatibility |
Description |
|
error |
String |
- |
Exception description, typically the |
|
stack |
String |
Base library: 2.7.4 |
Exception stack trace, typically 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, theonErrormethod inapp.jsalso listens for errors. -
When you use
my.onErrorto listen for page errors and the listener is registered on multiple pages without being closed, multiple listen events are triggered when an error occurs. We recommend that you callmy.offErrorto close the listener when the page is closed.