Dart lacks a way to create an error chain #56249
Labels
area-core-library
SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.
library-core
type-enhancement
A request for a change that isn't a bug
Hello!
One common use-case when handling error is to transform an error to add more context around it. This is often done by caching an exception, and throwing a new one.
The problem is twofold:
throw MyNewError())
or don't have a stacktrace pointing to the rethrown error (when usingError.throwWithStracktrace(...)
)One way to deal with that is to include the error/stacktrace of the original error in the
toString
of the new error.But that's not perfect.
For instance, it can easily confuse error reporting libraries. And debugging tools may have difficulties rendering the error in a readable way
One solution to that in Javascript is the
cause
field on errors:We could do the same with Dart's Error/Exception (maybe with an extra field for the StackTrace):
The text was updated successfully, but these errors were encountered: