Flutter Engine
The Flutter Engine
dart_error.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
7#include <atomic>
8
11
12namespace tonic {
13namespace DartError {
14const char kInvalidArgument[] = "Invalid argument.";
15} // namespace DartError
16
17namespace {
18void DefaultLogUnhandledException(Dart_Handle, Dart_Handle) {}
19std::atomic<DartError::UnhandledExceptionReporter> log_unhandled_exception =
20 DefaultLogUnhandledException;
21
22void ReportUnhandledException(Dart_Handle exception_handle,
23 Dart_Handle stack_trace_handle) {
24 log_unhandled_exception.load()(exception_handle, stack_trace_handle);
25}
26} // namespace
27
30 log_unhandled_exception.store(reporter);
31}
32
34 // Specifically handle UnhandledExceptionErrors first. These exclude fatal
35 // errors that are shutting down the vm and compilation errors in source code.
37 Dart_Handle exception_handle = Dart_ErrorGetException(handle);
38 Dart_Handle stack_trace_handle = Dart_ErrorGetStackTrace(handle);
39
40 ReportUnhandledException(exception_handle, stack_trace_handle);
41 return true;
42 } else if (Dart_IsFatalError(handle)) {
43 // An UnwindError designed to shutdown isolates. This is thrown by
44 // Isolate.exit. This is ordinary API usage, not actually an error, so
45 // silently shut down the isolate. The actual isolate shutdown happens in
46 // DartMessageHandler::UnhandledError.
47 return true;
48 } else if (Dart_IsError(handle)) {
49 tonic::Log("Dart Error: %s", Dart_GetError(handle));
50 return true;
51 } else {
52 return false;
53 }
54}
55
57 if (Dart_IsCompilationError(handle)) {
59 } else if (Dart_IsApiError(handle)) {
60 return kApiErrorType;
61 } else if (Dart_IsError(handle)) {
62 return kUnknownErrorType;
63 } else {
64 return kNoError;
65 }
66}
67
69 if (Dart_IsCompilationError(handle)) {
70 return 254; // dart::bin::kCompilationErrorExitCode
71 } else if (Dart_IsApiError(handle)) {
72 return 253; // dart::bin::kApiErrorExitCode
73 } else if (Dart_IsError(handle)) {
74 return 255; // dart::bin::kErrorExitCode
75 } else {
76 return 0;
77 }
78}
79
80} // namespace tonic
reporter
Definition: FontMgrTest.cpp:39
DART_EXPORT Dart_Handle Dart_ErrorGetStackTrace(Dart_Handle handle)
DART_EXPORT bool Dart_IsApiError(Dart_Handle handle)
struct _Dart_Handle * Dart_Handle
Definition: dart_api.h:258
DART_EXPORT bool Dart_IsFatalError(Dart_Handle handle)
DART_EXPORT bool Dart_IsUnhandledExceptionError(Dart_Handle handle)
DART_EXPORT Dart_Handle Dart_ErrorGetException(Dart_Handle handle)
DART_EXPORT bool Dart_IsError(Dart_Handle handle)
DART_EXPORT const char * Dart_GetError(Dart_Handle handle)
DART_EXPORT bool Dart_IsCompilationError(Dart_Handle handle)
const char kInvalidArgument[]
Definition: dart_error.cc:14
void(*)(Dart_Handle, Dart_Handle) UnhandledExceptionReporter
Definition: dart_error.h:15
DartErrorHandleType GetErrorHandleType(Dart_Handle handle)
Definition: dart_error.cc:56
void SetUnhandledExceptionReporter(DartError::UnhandledExceptionReporter reporter)
Definition: dart_error.cc:28
int GetErrorExitCode(Dart_Handle handle)
Definition: dart_error.cc:68
DartErrorHandleType
Definition: dart_error.h:67
@ kApiErrorType
Definition: dart_error.h:70
@ kCompilationErrorType
Definition: dart_error.h:71
@ kUnknownErrorType
Definition: dart_error.h:69
@ kNoError
Definition: dart_error.h:68
bool CheckAndHandleError(Dart_Handle handle)
Definition: dart_error.cc:33
void Log(const char *format,...)
Definition: log.cc:19