Skip to content
Merged
Show file tree
Hide file tree
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
Prev Previous commit
Next Next commit
update readme
  • Loading branch information
marandaneto committed Oct 28, 2020
commit 61304a54e349178fea81b2ef09386ab25a2a6e76
57 changes: 36 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,18 @@ Sentry.init((options) => options.dsn = '___PUBLIC_DSN___');
In an exception handler, call `captureException()`:

```dart
try {
aMethodThatMightFail();
} catch (exception, stackTrace) {
Sentry.captureException(exception, stackTrace: stackTrace);
import 'dart:async';
import 'package:sentry/sentry.dart';

void main() async {
try {
aMethodThatMightFail();
} catch (exception, stackTrace) {
await Sentry.captureException(
exception,
stackTrace: stackTrace,
);
}
}
```

Expand All @@ -80,35 +88,42 @@ try {

```dart
import 'dart:async';

import 'package:flutter/material.dart';

import 'package:sentry/sentry.dart';

// Wrap your 'runApp(MyApp())' as follows:

void main() async {
runZonedGuarded(
() => runApp(MyApp()),
(error, stackTrace) {
Sentry.captureException(
exception: error,
stackTrace: stackTrace,
);
},
);
Future<void> main() async {
runZonedGuarded<Future<void>>(() async {
runApp(MyApp());
}, (exception, stackTrace) async {
await Sentry.captureException(
exception,
stackTrace: stackTrace,
);
});
}
```

- For Flutter-specific errors (such as layout failures), use [FlutterError.onError][flutter_error]. For example:

```dart
import 'package:flutter/foundation.dart';
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:sentry/sentry.dart';

FlutterError.onError = (details, {bool forceReport = false}) {
Sentry.captureException(
exception: details.exception,
stackTrace: details.stack,
);
};
// Wrap your 'runApp(MyApp())' as follows:

Future<void> main() async {
FlutterError.onError = (FlutterErrorDetails details) async {
await Sentry.captureException(
details.exception,
stackTrace: details.stack,
);
};
}
```

- Use `Isolate.current.addErrorListener` to capture uncaught errors
Expand Down
24 changes: 24 additions & 0 deletions dart/lib/src/protocol/test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'dart:async';
import 'package:sentry/sentry.dart';

// Wrap your 'runApp(MyApp())' as follows:

void main() async {
runZonedGuarded(
() => runApp(MyApp()),
(error, stackTrace) {
Sentry.captureException(
exception: error,
stackTrace: stackTrace,
);
},
);
}


}

class MyApp {
runApp(MyApp myApp) {
}
}
22 changes: 22 additions & 0 deletions flutter/example/lib/test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:sentry/sentry.dart';

// Wrap your 'runApp(MyApp())' as follows:

Future<void> main() async {
FlutterError.onError = (FlutterErrorDetails details) async {
await Sentry.captureException(
details.exception,
stackTrace: details.stack,
);
};
}

class MyApp extends StatefulWidget {
@override
State<StatefulWidget> createState() {
// TODO: implement createState
throw UnimplementedError();
}
}