Exception and finally question

Tung Wai Yip tungwaiyip at yahoo.com
Fri Apr 25 13:56:10 EDT 2003


On Thu, 24 Apr 2003 23:18:57 +0000 (UTC), Benjamin Hartshorne
<ben at hal.rescomp.berkeley.edu> wrote:

>Tung Wai Yip <tungwaiyip at yahoo.com> wrote:
>> Hello,
>
>> How to I access the exception object in a handler?
>
>> try:
>>     raise NameError, 'HiThere'
>> except NameError:
>>     #how to print the message 'Hi There' here?
>
>try:
>  raise NameError, "HiThere'
>except NameError, whoshere:
>  print whoshere, "how are you?"
>
>-ben

Thank you. I didn't realize this syntax because I have it mixed up
with the tuple version.

 except (RuntimeError, TypeError, NameError):

By the way, mixing tuple with the exception target would look more
confusing (at least to me with Java background).

 # I guess we can code this way
 except (RuntimeError, TypeError, NameError), e:

 # this probably won't mix.
 except ,e:


tung





More information about the Python-list mailing list