To catch such an error, use PlatformDispatcher.instance.onError.

Handling all types of errors

Say you want to exit application on any exception and to display
a custom error widget whenever a widget building fails - you can base
your errors handling on next code snippet: