ExceptionWatcher class final
Hooks both FlutterError.onError and PlatformDispatcher.instance.onError
to capture all unhandled exceptions in a Flutter app.
This matches the Flutter "Handling errors" canonical pattern:
- FlutterError.onError covers synchronous framework + widget errors (null dereferences, assertion failures, layout overflows, etc.).
PlatformDispatcher.instance.onErrorcovers asynchronous errors, errors from other isolates, and plugin-originated errors; paths that never reach FlutterError.onError.
Both hooks chain-preserve any previously-registered handler (Sentry,
Bugsnag, etc.) so that downstream observability is never silently masked.
The PlatformDispatcher.onError handler chain-preserves the previous
handler's return value (_previousPlatformOnError?.call(...) ?? true).
When a previously-registered handler returns false, this watcher also
returns false, which propagates the error to the native platform crash
handler. This is the Sentry-friendly contract: crumbs captures the
record AND lets the downstream library decide whether the error is fatal.
When no previous handler exists, the default is true (handled), so an
error crumbs recorded does not also reach the native crash handler.
Recording never stands between an error and the previous handler: when
recording throws (an error whose toString throws), the previous handler
still runs and the recording failure propagates after it.
On uninstall, both handlers are restored to exactly the values they held before install was called. Calling install while already installed is a no-op (idempotent).
- Implemented types
Constructors
Properties
Methods
-
install(
) → void -
Wire the watcher's listening hook (event subscription, override, etc.).
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
uninstall(
) → void -
Tear down the hook (test isolation).
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited