Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add an example for FlutterError.onError
  • Loading branch information
filiph committed Aug 28, 2019
commit 85ca3fc45981a0987dbc3083b60e555975992aed
24 changes: 20 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,26 @@ main() async {

## Tips for catching errors

- use a `try/catch` block
- create a `Zone` with an error handler, e.g. using [runZoned][run_zoned]
- in Flutter, use [FlutterError.onError][flutter_error]
- use `Isolate.current.addErrorListener` to capture uncaught errors in the root zone
- Use a `try/catch` block, like in the example above.
- Create a `Zone` with an error handler, e.g. using [runZoned][run_zoned].
- In Flutter, use [FlutterError.onError][flutter_error]. For example:

```dart
var sentry = SentryClient(dsn: "https://...");
FlutterError.onError = (details, {bool forceReport = false}) {
try {
sentry.captureException(
exception: details.exception,
stackTrace: details.stack,
);
} finally {
// Also use Flutter's default error reporting.
FlutterError.dumpErrorToConsole(details, forceReport: forceReport);
}
};
```
- Use `Isolate.current.addErrorListener` to capture uncaught errors
in the root zone.

[run_zoned]: https://api.dartlang.org/stable/dart-async/runZoned.html
[flutter_error]: https://docs.flutter.io/flutter/foundation/FlutterError/onError.html
Expand Down