Crash Analysis API

Updated at:

This topic describes the APIs for Crash Analytics and explains how to use them.

1. Report a custom exception

Feature description

Custom exceptions are errors that you define in your application. During runtime, your business code can catch these exceptions and report them to the Crash Analytics service for data collection.

Scenarios

This feature is useful for scenarios where you need to actively catch errors and collect data for analysis, such as:

  1. Core business features where you have implemented error catching and need to report the data.

  2. Asynchronous business flows that are invisible to the user, where you need to catch and report errors.

  3. Low-probability error handling for system APIs, where you can report errors to identify potential online issues.

Interface definition

The following definitions apply:

export interface CrashAnalysisApi extends IPlugin {
  reportCustomError(error: string | Error): void;
}

The error parameter is the custom exception to report. The value can be a string or an Error type.

Code example

crashAnalysisApi.reportCustomError("A string as a custom error");
crashAnalysisApi.reportCustomError(new Error('A custom error'));
try {
  await http.createHttp().request("");
} catch (e) {
  crashAnalysisApi.reportCustomError(e as Error);
}