Which exception should I raise on bad/illegal argument combinations in Python? -


i wondering best practices indicating invalid argument combinations in python. i've come across few situations have function so:

def import_to_orm(name, save=false, recurse=false):     """     :param name: name of external entity import.     :param save: save orm object before returning.     :param recurse: attempt import associated objects well. because         need original object have key relate to, save must         `true` recurse `true`.     :raise badvalueerror: if `recurse , not save`.     :return: orm object.     """     pass 

the annoyance every package has own, differing badvalueerror. know in java there exists java.lang.illegalargumentexception -- understood creating own badvalueerrors in python or there another, preferred method?

i raise valueerror, unless need more specific exception..

def import_to_orm(name, save=false, recurse=false):     if recurse , not save:         raise valueerror("save must true if recurse true") 

there's no point in doing class badvalueerror(valueerror):pass - custom class identical in use valueerror, why not use that?


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -