Last active
March 2, 2021 06:16
-
-
Save madmag77/e67aa709e1792e134756db3c2e1683e6 to your computer and use it in GitHub Desktop.
[Dart article] Handling exceptions in synchronous code
This file contains 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
try { | |
final _ = 100 ~/ 0; | |
} on IntegerDivisionByZeroException { | |
print('Cant divide to zero'); | |
} finally { | |
print('Clean-up done 1'); | |
} | |
print('\n\n'); | |
try { | |
throw FormatException('format is wrong'); | |
} on IntegerDivisionByZeroException { | |
print('Cant divide to zero'); | |
} on FormatException catch (e) { | |
print('Format exceptions $e'); | |
} finally { | |
print('Clean-up done 2'); | |
} | |
print('\n\n'); | |
try { | |
print('Allocate something 3'); | |
throw 'Other error occurred'; | |
} on IntegerDivisionByZeroException { | |
print('Cant divide to zero'); | |
} on FormatException catch (e) { | |
print('Format exceptions: $e'); | |
} catch (e, s) { | |
print('Unknown exceptions: $e, with stack: \n$s'); | |
rethrow; | |
} finally { | |
print('Clean-up something 3'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment