Last active
April 11, 2022 16:09
-
-
Save hpoul/8fef76c5ba1c76a23042025097ed3e0a to your computer and use it in GitHub Desktop.
Catch error using catchError in a future and throw another type - https://stackoverflow.com/questions/55596257/catch-error-using-catcherror-in-a-future-and-throw-another-type/55596655#55596655
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
class FirstError { } | |
class SecondError { } | |
Future<void> someApi() { | |
return Future(() { | |
throw FirstError(); | |
}).catchError((error, stackTrace) { | |
print("inner: $error"); | |
// although `throw SecondError()` has the same effect. | |
return Future.error(SecondError()); | |
}); | |
} | |
void main() { | |
someApi() | |
.then((val) { print("success"); }) | |
.catchError((error, stackTrace) { print("outer: $error"); }); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment