<p>我想捕捉一个特定的ValueError,而不仅仅是任何ValueError。<br/>
我试过这样的方法:</p>
<pre><code>try: maquina['WPF'] = macdat(ibus, id, 'WPF')
except: ValueError, 'For STRING = ’WPF’, this machine is not a wind machine.':
pass
</code></pre>
<p>但它引发了一个语法错误:无法赋值给literal。<br/>
然后我试着:</p>
<pre><code>try: maquina['WPF'] = macdat(ibus, id, 'WPF')
except ValueError, e:
if e != 'For STRING = ’WPF’, this machine is not a wind machine.':
raise ValueError, e
</code></pre>
<p>但这引发了一个例外,即使这是我想避免的。</p>