Which exception should I raise on bad/illegal argument combinations in Python?
I would objective raise ValueError, except you want a more specific exception..
def import_to_orm(name, save=False, recurse=False): if recurse and not save: raise ValueError("save must be True if recurse is True")
There is actually no point in doing class BadValueError(ValueError):pass – your tradition class is matching in use to ValueError, so why not use that in python?
Just inherit from ValueError:
class IllegalArgumentError(ValueError): pass
It is typically higher to form your own exceptions, however inherit from a intrinsic one, that is as about to what you would like as doable.
If you would like to catch that specific error, it’s useful to possess a reputation.