my.onError

更新时间:
复制 MD 格式

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 message field of the Error object.

stack

String

Base library: 2.7.4

Exception stack trace, typically the stack field of the Error object.

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);
 }
})
Note
  • If you use my.onError to listen for errors, the onError method in app.js also listens for errors.

  • When you use my.onError to 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 call my.offError to close the listener when the page is closed.