Skip to content
This repository has been archived by the owner on Nov 7, 2023. It is now read-only.

Commit

Permalink
refactor: catch all uncaught errors
Browse files Browse the repository at this point in the history
  • Loading branch information
zyrouge committed Oct 23, 2021
1 parent 85a84f1 commit 39ff8d7
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:async';
import 'package:flutter/material.dart';
import './plugins/app_lifecycle.dart';
import './plugins/database/database.dart';
Expand All @@ -20,7 +21,23 @@ Future<void> main(final List<String> args) async {
}

Logger.of('main').info('Starting "MainApp"');
runApp(const MainApp());

runZonedGuarded(() async {
FlutterError.onError = (final FlutterErrorDetails details) {
FlutterError.presentError(details);
Logger.of('main').error(
'Uncaught error: ${details.exceptionAsString()}',
details.stack,
);
};

runApp(const MainApp());
}, (final Object error, final StackTrace stack) {
Logger.of('main').error(
'Uncaught error: ${error.toString()}',
stack,
);
});
}

class MainApp extends StatefulWidget {
Expand Down

0 comments on commit 39ff8d7

Please sign in to comment.