Created
June 15, 2016 17:16
-
-
Save cemsbr/cfa00ea8382a0962a2437ab01da6d44f to your computer and use it in GitHub Desktop.
Throw multiple validation errors
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
# based on http://stackoverflow.com/questions/6470428/catch-multiple-exceptions-in-one-line-except-block | |
class ValidationError(Exception): | |
pass | |
class ValidationErrors(ValidationError): | |
def __str__(self): | |
return ' '.join(str(e) for e in self.args[0]) | |
e1 = ValidationError('Error 1.') | |
e2 = ValidationError('Error 2.') | |
errors = [e1, e2] | |
raise ValidationErrors(errors) | |
# Run and see "Error 1. Error 2." as error message |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment