With Sentry set up, you can begin to report errors. Since you don’t want to report errors to Sentry during development, first create a function that lets you know whether you’re in debug or production mode.
1 2 3 4 5 6 7 8 9 10 11 |
bool get isInDebugMode { // Assume you're in production mode. bool inDebugMode = false; // Assert expressions are only evaluated during development. They are ignored // in production. Therefore, this code only sets `inDebugMode` to true // in a development environment. assert(inDebugMode = true); return inDebugMode; } |
Next, use this function in combination with the SentryClient
to report errors when the app is in production mode.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
Future<void> _reportError(dynamic error, dynamic stackTrace) async { // Print the exception to the console. print('Caught error: $error'); if (isInDebugMode) { // Print the full stacktrace in debug mode. print(stackTrace); } else { // Send the Exception and Stacktrace to Sentry in Production mode. _sentry.captureException( exception: error, stackTrace: stackTrace, ); } } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.