my.onError

Listen for the event that errors occur in the mini program. Currently only JS errors are supported. The triggered time and required parameters are the same with those of the onError() method.

Sample code

Sample for general errors:

copy
// .js
App({
  onLaunch() {
    // Type of error is String.
    my.onError(function(error) {
      // Errors occur when running the mini program.
      console.error(error);
    });
  }
})

Sample for JS errors:

copy
onShow: function() {

    // Errors occur when running the mini program.
    my.onError(function(error) {
      // Error message displayed on the page
      console.warn(error, '1212');
    });
  }

Parameters

Property

TypeDescription
callbackFunctionThe callback function for the event that JS errors occur in the mini program. 

Returned value

Property

TypeDescription

error

String

Error message.