init static method
void
init({
- OnError? onError,
Implementation
static void init({OnError? onError}) {
final FlutterExceptionHandler? rawOnError = FlutterError.onError;
// 捕获Flutter 框架运行时的错误,包括构建期间、布局期间和绘制期间
ExceptionTrace.handler = (FlutterErrorDetails details) {
if (details.exception is ApmFlutterError) {
ExceptionTrace.handleApmSdkException(
details.exception, details.stack.toString());
} else {
nativeTryCatch(handler: () {
final library = details.library;
final bool isWidgetsLibrary =
library is String && 'widgets library'.compareTo(library) == 0;
ExceptionDataProcessor().push(
exceptionData: ExceptionData(
msg: details.exception.toString(),
stack: _stackSplit(stackStr: details.stack.toString()),
type: details.exception.runtimeType.toString(),
level: isWidgetsLibrary
? 'ErrorWidget'
: _getErrorType(details.exception),
),
autoCollection: true);
if (onError != null) {
onError(details.exception, details.stack);
}
});
}
return rawOnError!(details);
};
FlutterError.onError = handler;
}