Exception as the primary error handling mechanism?

r0g aioe.org at technicalbloke.com
Tue Jan 5 14:06:20 CET 2010


Dave Angel wrote:
> 
> 
> r0g wrote:
>> <snip>
>>
>> Maybe, although I recently learned on here that one can't rely on assert
>>  statements in production code, their intended use is to aid debugging
>> and testing really.
>>
>>   
> Hopefully, what you learned is that you can't use assert() in production
> code to validate user data.  It's fine to use it to validate program
> logic, because that shouldn't still need testing in production.
> 
> <snip>
> 
> DaveA



Well maybe I didn't quite get it then, could you explain a bit further?

My understanding was that asserts aren't executed at all if python is
started with the -O or -OO option, or run through an optimizer. If
that's the case how can you expect it to validate anything at all in
production? Do you mean for debugging in situ or something? Could you
maybe give me an example scenario to illustrate your point?

Cheers,

Roger.



More information about the Python-list mailing list