Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'dart:async';
- void main() {
- bar();
- baz();
- }
- Future<void> bar() async {
- try {
- // uncomment things and observe the output
- // await throwFoo();
- // await futureErrorFoo();
- await futureErrorExceptionFoo();
- } on Exception catch (e) {
- print('type: ${e.runtimeType} string: ${e.toString()}');
- } catch (e) {
- print('type: ${e.runtimeType} string: ${e.toString()}');
- }
- }
- void baz() {
- throwFoo().catchError((e) {
- print('type: ${e.runtimeType} string: ${e.toString()}');
- });
- futureErrorFoo().catchError((e) {
- print('type: ${e.runtimeType} string: ${e.toString()}');
- });
- futureErrorExceptionFoo().catchError((e) {
- print('type: ${e.runtimeType} string: ${e.toString()}');
- });
- }
- Future<void> throwFoo() async {
- throw Exception('foo exception');
- }
- Future<void> futureErrorFoo() async {
- return Future.error('test');
- }
- Future<void> futureErrorExceptionFoo() async {
- return Future.error(Exception('test'));
- }
Add Comment
Please, Sign In to add comment