[Baypiggies] Python way to avoid usage of raise

Glen Jarvis glen at glenjarvis.com
Thu Oct 7 23:18:45 CEST 2010


EXCELLENT NEWS, Nick!!!

Raising is in PEP-8 (http://www.python.org/dev/peps/pep-0008/) and I
personally couldn't find a pythonic way to do this otherwise...

Glen

On Wed, Oct 6, 2010 at 2:50 PM, Nick S Kanakakorn <bbdada at gmail.com> wrote:

> There is a happy news here today.  The use of raise exception is allowed
> again after I put some coding in using this convention:
>
> exitcode, actual_result = f1()
> if exitcode < 0: return exitcode
> .... continue something useful with actual_result
> exitcode, actual_result = f1()
>
>
>
> On Tue, Oct 5, 2010 at 7:15 PM, Nick S Kanakakorn <bbdada at gmail.com>wrote:
>
>> Hi,
>>
>> My work place has imposed a rules for no use of exception (catching is
>> allowed).  If I have code like this
>>
>> def f1()
>>   if bad_thing_happen():
>>      raise Exception('bad stuff')
>>   ...
>>   return something
>>
>> I could change it to
>>
>> def f1()
>>   if bad_thing_happen():
>>     return [-1, None]
>>   ...
>>   return [0, something]
>>
>> f1 caller would be like this
>>
>> def f1_caller():
>>   code, result = f1(param1)
>>   if code < 0:
>>     return code
>>   actual_work1()
>>   # call f1 again
>>   code, result = f1(param2)
>>   if code < 0:
>>     return code
>>   actual_work2()
>>   ...
>>
>> Are there more elegant ways than this in Python ?
>>
>> Thanks,
>> Nick K
>>
>>
>
>
> --
> -Nick Kanakakorn
>
> _______________________________________________
> Baypiggies mailing list
> Baypiggies at python.org
> To change your subscription options or unsubscribe:
> http://mail.python.org/mailman/listinfo/baypiggies
>



-- 
Whatever you can do or imagine, begin it;
boldness has beauty, magic, and power in it.

-- Goethe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/baypiggies/attachments/20101007/476ad927/attachment-0001.html>


More information about the Baypiggies mailing list