catching exceptions

Steven D'Aprano steve at REMOVE.THIS.cybersource.com.au
Sat Dec 16 07:34:41 EST 2006


On Sat, 16 Dec 2006 17:36:00 +0530, Amit Khemka wrote:

> If I gather correctly, i guess in case of errors/exceptions in a class
> function, you want to get the error string. One thing that comes
> straight to my mind is, in such a case use a return statement in
> functions with two arguments.
> 
> for example:
> def foo(self, value):
>     try:
>         a.x = value
>         return True, ''
>     except ValueError:  return False, 'Float conversion error: %s' %(value)
> 
> and when ever u call the function, check the first return value, It is
> false then alert/print the error message.

Oh lordy, that is _so_ 1980s programming practice!!!

I'm not saying that it is never a good idea, but avoiding that sort of
thing is one of the reasons exceptions were created!


-- 
Steven.




More information about the Python-list mailing list