Flutter Engine
The Flutter Engine
dart_error.h
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
5#ifndef LIB_TONIC_LOGGING_DART_ERROR_H_
6#define LIB_TONIC_LOGGING_DART_ERROR_H_
7
8#include "third_party/dart/runtime/include/dart_api.h"
9
11
12namespace tonic {
13
14namespace DartError {
16
17extern const char kInvalidArgument[];
18} // namespace DartError
19
20/// Check if a Dart_Handle is an error or exception.
21///
22/// If it is an error or exception, this method will return true.
23///
24/// If it is an unhandled error or exception, the closure in
25/// |SetUnhandledExceptionReporter| is called. The DartVMInitializer provides
26/// that closure, which checks with UIDartState::Current() if it is available
27/// and falls back to simply printing the exception and stack to an error log if
28/// the settings callback is not provided.
29///
30/// If UIDartState::Current() is available, it can provide an onError callback
31/// that forwards to `PlatformConfiguration.instance.onError`. If that callback
32/// is not set, the callback from `Settings.unhandled_exception_callback` is
33/// invoked. If that callback is not set, a simple error log is
34/// printed.
35///
36/// If the PlatformDispatcher callback throws an exception, the at least two
37/// separate exceptions and stacktraces will be handled by either the
38/// Settings.unhandled_exception_callback or the error printer: one for the
39/// original exception, and one for the exception thrown in the callback. If the
40/// callback returns false, the original exception and stacktrace are logged. If
41/// it returns true, no additional logging is done.
42///
43/// Leaving the PlatformDispatcher.instance.onError callback unset or returning
44/// false from it matches the behavior of Flutter applications before the
45/// introduction of PlatformDispatcher.onError, which is to print to the error
46/// log.
47///
48/// Dart has errors that are not considered unhandled exceptions, such as
49/// Dart_* API usage errors. In these cases, `Dart_IsUnhandledException` returns
50/// false but `Dart_IsError` returns true. Such errors are logged to stderr or
51/// some similar mechanism provided by the platform such as logcat on Android.
52/// Depending on which type of error occurs, the process may crash and the Dart
53/// isolate may be unusable. Errors that fall into this category include
54/// compilation errors, Dart API errors, and unwind errors that will terminate
55/// the Dart VM.
56///
57/// Historically known as LogIfError.
59
60/// The fallback mechanism to log errors if the platform configuration error
61/// handler returns false.
62///
63/// Normally, UIDartState registers with this method in its constructor.
66
72};
73
75
77
78} // namespace tonic
79
80#endif // LIB_TONIC_DART_ERROR_H_
reporter
Definition: FontMgrTest.cpp:39
struct _Dart_Handle * Dart_Handle
Definition: dart_api.h:258
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