Last active
January 21, 2024 15:14
-
-
Save hawkkiller/14dccb4e2335176fdebd328d1c723808 to your computer and use it in GitHub Desktop.
Error-handling example #1
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
void main() { | |
try { | |
sendPost(); | |
// on without catch clause | |
} on LackOfPrivilegesException { | |
print("You don't have enough privileges."); | |
// on with catch clause | |
} on ValidationException catch (e) { | |
print('Please verify entered fields: ${e.fields}'); | |
// general catch clause | |
} catch (e) { | |
print('Error occured: $e'); | |
} | |
} | |
void sendPost() { | |
throw LackOfPrivilegesException(); | |
} | |
class LackOfPrivilegesException implements Exception {} | |
class ValidationException implements Exception { | |
final List<String> fields; | |
const ValidationException(this.fields); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment