Skip to content

Instantly share code, notes, and snippets.

@ali2236
Last active December 3, 2020 20:07
Show Gist options
  • Save ali2236/4000ed0f1e170615923f6c1e7f5f468a to your computer and use it in GitHub Desktop.
Save ali2236/4000ed0f1e170615923f6c1e7f5f468a to your computer and use it in GitHub Desktop.
how to chain exceptions in dart.
import 'dart:async';
void main() {
runZoned(() {
try {
try {
throw 'exception 1';
} catch (e) {
throw LinkedException('exception 2',e);
}
} catch (e) {
throw LinkedException('exception 3',e);
}
}, onError: print);
}
class LinkedException implements Exception {
final String cause;
final exception;
LinkedException(this.cause,[this.exception]);
@override
String toString() => '$cause <- $exception';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment