Last active
January 22, 2020 16:44
-
-
Save savioserra/71c2929a60f40dc5bd474c1fab81f284 to your computer and use it in GitHub Desktop.
Error sim
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 User { | |
final String name; | |
User({this.name}); | |
} | |
/// Exemplo de erro | |
class UserNotFound implements Exception {} | |
User getUser() { | |
var error = true; // Supondo que ocorreu um erro num fetch | |
if (error) { | |
throw UserNotFound(); // lançando o erro | |
} | |
return User(name: "Fulano"); | |
} | |
main() { | |
try { | |
var user = getUser(); // está tipada corretamente | |
} on UserNotFound { | |
// capturando o erro lançado do tipo "UserNotFound" | |
print("ops"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment