Optimize flag question

bonono at gmail.com bonono at gmail.com
Sat Feb 25 20:56:42 EST 2006


Steve Holden wrote:
> > Some other functions rely on the AssertionError exception to indicate to
> > the user that something went wrong instead of using a user defined
> > exception.
> >
>
> The real problem here is that you appear to be using AssertionError in
> an inappropriate way. If some caller passes an incorrect argument to
> your function, raise a ValueError. If you are passed the wrong type of
> data, raise a TypeError. And so on. Or, as you imply you thought about,
> raise a user-defined error.
>
> Generally speaking you should reserve assert for circumstances where you
> expect some invariant condition to be true. Otherwise use an "if"
> statement and raise some other exception if the condition is True.
>
What would be the occasion that AssertionError be the right exception
to raise then ?




More information about the Python-list mailing list