Skip to content

Commit

Permalink
Log exception in addition to the stack trace for unhandled exceptions. (
Browse files Browse the repository at this point in the history
flutter#20935)

* Log exception in addition to the stack trace for unhandled exceptions.

Having exception logged can be especially useful when stack trace is blank.
  • Loading branch information
aam authored Sep 2, 2020
1 parent 8f3f711 commit 873c007
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion third_party/tonic/logging/dart_error.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ const char kInvalidArgument[] = "Invalid argument.";

bool LogIfError(Dart_Handle handle) {
if (Dart_IsUnhandledExceptionError(handle)) {
Dart_Handle exception_handle = Dart_ErrorGetException(handle);
const std::string exception =
tonic::StdStringFromDart(Dart_ToString(exception_handle));
Dart_Handle stack_trace_handle = Dart_ErrorGetStackTrace(handle);
const std::string stack_trace =
tonic::StdStringFromDart(Dart_ToString(stack_trace_handle));
tonic::Log("Dart Unhandled Exception: %s", stack_trace.c_str());
tonic::Log("Dart Unhandled Exception: %s, stack trace: %s",
exception.c_str(), stack_trace.c_str());
return true;
} else if (Dart_IsError(handle)) {
tonic::Log("Dart Error: %s", Dart_GetError(handle));
Expand Down

0 comments on commit 873c007

Please sign in to comment.