Skip to content

Provide an onError handler that will crash the app #11206

@tvolkert

Description

@tvolkert

The default onError handler dumps the error to the console. On release builds, it's very likely that an uncaught exception leaves the app in an unusable/unpredictable state. In such cases, it's common for the app developer to prefer that the app crashes rather than it continue in such a state. Crashing the app also triggers existing flows like built-in crash reporting.

The developer can currently stop the app by calling exit([int code]) from dart:io, but doing so looks like a "clean exit" to the OS, even if a non-zero exit code was used. Rather, we want to trigger an exit that the OS will detect as a crash, with associated error data.

I suggest we add support for an onError handler that will crash the app in such a way as to tie the uncaught Dart exception to the crash.

I see two possible ways to accomplish this:

  1. Via a CrashOnDartExceptionPlugin that would set onError to a handler that forwards the exception to the OEM code via our message passing bus, at which point the OEM code would crash the app.
  2. We provide a crash([FlutterErrorDetails details]) method that app developers could set as the onError handler. The implementation would probably use the same mechanics as option 1, but using built-in SystemChannels.X.

I think option 2 is probably the way to go.

@Hixie

Metadata

Metadata

Assignees

No one assigned

    Labels

    engineflutter/engine related. See also e: labels.frameworkflutter/packages/flutter repository. See also f: labels.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions