擅长:python、mysql、java
<p>使用一个空的<code>except</code>很少是一个好主意,但这是一个非常罕见的情况,主要是因为您有一个备份,如果出于任何原因,您无法导入系统<code>sge</code>:</p>
<pre><code>try:
import sge_execution_engine as execution_engine
except:
print "Use local execution engine because SGE support is missing!"
print sys.exc_info() # Print out the exception message
import local_execution_engine as execution_engine
</code></pre>
<p>注意,现在只需要一个<code>except</code>子句。在</p>
<p>处理向用户获取这些信息的更好方法可能是先打印出来,然后使用<a href="https://docs.python.org/3/library/logging.html" rel="nofollow">logging</a>模块创建一个永久记录:</p>
^{pr2}$
<p>然后在<code>except</code>子句中添加:</p>
<pre><code> logger.exception('unable to import sge')
</code></pre>
<p>您的消息以及实际的异常都将保存在日志文件中。在</p>