Should a validate method throw an exception?

Viewed 5421

I've implemented a little validation library which is used like this:

domain_object.validate()

# handle validation errors in some way ...
if domain_object.errors:
    for error in domain_object.errors:
        print(error)

validate() performs the checks and populates a list called errors.

I know from other validation libraries that they throw exception when validation is performed unsuccessfully. Error messages would be passed as an exception property.

What approach is better? Is it advantageous to throw validation exceptions?

2 Answers
Related