擅长:python、mysql、java
<p>使用<code>as</code>语句。您可以在<a href="http://docs.python.org/tutorial/errors.html#handling-exceptions">Handling Exceptions</a>中阅读更多关于此的信息。</p>
<pre class="lang-py prettyprint-override"><code>>>> try:
... print(a)
... except NameError as e:
... print(dir(e)) # print attributes of e
...
['__cause__', '__class__', '__context__', '__delattr__', '__dict__', '__doc__', '__eq__',
'__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__',
'__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__',
'__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__traceback__', 'args',
'with_traceback']
</code></pre>