Last active
December 3, 2020 20:07
-
-
Save ali2236/4000ed0f1e170615923f6c1e7f5f468a to your computer and use it in GitHub Desktop.
how to chain exceptions in dart.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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