Is this the *right* way of exception handling?

Piotr Legiecki piotrlg at sci.pam.szczecin.pl
Fri Aug 3 06:21:59 EDT 2001


Hi

I wonder if the way I use exceptions is the right way or very problematic
one (anyway it works of course).

I have one class and fill it with a data. If data are wrong i raise my
exception:

class A:
  my_exception='my_exception'
.......
  def f(self,a):
     if a !=0
	raise my_exception, 'a must be 0'

def f1()
...
  try:
    x=A()
     x.f(1)
  except A.my_exception, val:
    print 'wow, eror', val
    #!!now, what to do here, i want to stop my program, but should clean
     something (close files etc) before, so sys.exit() is not a good idea
     another raise?

def main():
...
  use some resources, open files etc

  f1()

  close resources, files etc

Thanx
Piotr Legiecki



More information about the Python-list mailing list