擅长:python、mysql、java
<p>这是用Python和其他语言实现的异常原则。对于引发异常的函数,不需要<em>local</em>中的异常处理。你知道吗</p>
<p>如果一些本地处理是有意义的,就去做。如果您不能做任何有用的事情,就让异常进入调用堆栈,直到找到合适的异常处理程序。你知道吗</p>
<p><a href="http://docs.python.org/2/tutorial/errors.html#handling-exceptions" rel="nofollow">http://docs.python.org/2/tutorial/errors.html#handling-exceptions</a></p>
<hr/>
<p>如果只是为了记录异常而捕获异常,则可能需要重新引发它:</p>
<pre><code>try:
fileHandle = open(file, 'r')
except IOError:
print "Error: failed to open file %s" % (file, )
raise
</code></pre>
<p><a href="http://docs.python.org/2/tutorial/errors.html#raising-exceptions" rel="nofollow">http://docs.python.org/2/tutorial/errors.html#raising-exceptions</a></p>