I would like to handle an exception in the following way:
Suppose I need to handle a case where a program does something with
'a' , let's assume a simple case - print a
The problem is that sometimes a will be given to the program, and
sometimes not. So, I could say:
try:
print a
except NameError:
whatever...
I still want to continue the program assigning a='' so there will
be no exception. BUT - I want this to be a general mechanism i.e.
I would like to do something like:
try:
print a
except NameError:
eval(str(sys.exc_value) + " = ''")
This however, fails on a SyntaxError. I tryed it with repr() as well -
no can do...
Suggestions anyone?
Thanks a lot,
Benny.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Benny Shomer
External Biological Liasion Officer,
EMBL outstation - The EBI,
Hinxton Hall, Hinxton,Cambridge CB10 1RQ, UK
Tel: +44-223-494437
Fax: +44-223-494468
Email: bshomer@EBI.ac.uk
http://www.ebi.ac.uk/ebi_docs/staff/benny.html
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~