Skip to content

Instantly share code, notes, and snippets.

@cemsbr
Created June 15, 2016 17:16
Show Gist options
  • Save cemsbr/cfa00ea8382a0962a2437ab01da6d44f to your computer and use it in GitHub Desktop.
Save cemsbr/cfa00ea8382a0962a2437ab01da6d44f to your computer and use it in GitHub Desktop.
Throw multiple validation errors
# 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