[Baypiggies] Python way to avoid usage of raise
Nick S Kanakakorn
bbdada at gmail.com
Wed Oct 6 23:50:52 CEST 2010
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/baypiggies/attachments/20101006/1314abb7/attachment.html>
More information about the Baypiggies
mailing list