All Products
Search
Document Center

Mobile Platform as a Service:my.onError

Last Updated:Jan 12, 2024

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

stack

String

Base database: 2.7.4

The exception stack, which is generally 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, onError methods in the app.js will also listen for errors.

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