Guest User

Untitled

a guest
Oct 23rd, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. import 'dart:async';
  2.  
  3. void main() {
  4. bar();
  5. baz();
  6. }
  7.  
  8. Future<void> bar() async {
  9. try {
  10. // uncomment things and observe the output
  11. // await throwFoo();
  12. // await futureErrorFoo();
  13. await futureErrorExceptionFoo();
  14. } on Exception catch (e) {
  15. print('type: ${e.runtimeType} string: ${e.toString()}');
  16. } catch (e) {
  17. print('type: ${e.runtimeType} string: ${e.toString()}');
  18. }
  19. }
  20.  
  21. void baz() {
  22. throwFoo().catchError((e) {
  23. print('type: ${e.runtimeType} string: ${e.toString()}');
  24. });
  25. futureErrorFoo().catchError((e) {
  26. print('type: ${e.runtimeType} string: ${e.toString()}');
  27. });
  28. futureErrorExceptionFoo().catchError((e) {
  29. print('type: ${e.runtimeType} string: ${e.toString()}');
  30. });
  31. }
  32.  
  33. Future<void> throwFoo() async {
  34. throw Exception('foo exception');
  35. }
  36.  
  37. Future<void> futureErrorFoo() async {
  38. return Future.error('test');
  39. }
  40.  
  41. Future<void> futureErrorExceptionFoo() async {
  42. return Future.error(Exception('test'));
  43. }
Add Comment
Please, Sign In to add comment