[Baypiggies] Python way to avoid usage of raise

Nick S Kanakakorn bbdada at gmail.com
Wed Oct 6 04:15:50 CEST 2010


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/baypiggies/attachments/20101005/40b6c7cd/attachment.html>


More information about the Baypiggies mailing list