2016-09-16 61 views
0

举例来说,我使用wave模块 。提升异常波形python

 import wave 
    origAudio = wave.open("son.wav",'r') 

获取输出

 raise Error, 'file does not start with RIFF id' 
     wave.Error: file does not start with RIFF id 

我知道文件是不是不好,但我想提出这个异常或此错误

+2

已经为您提出异常'错误'。你的意思是抓住并重新制定一个不同的? – RedX

+0

@RedX我想在这个错误后程序继续转动 –

回答

1

如果您希望继续之后的厚望已经提升你必须抓住它:

import wave 
try: 
    origAudio = wave.open("son.wav",'r') 
except wave.Error as e: 
    # if you get here it means an error happende, maybe you should warn the user 
    # but doing pass will silently ignore it 
    pass 
+0

这不工作,因为它不知道错误 –

+0

它可能是'wave.Error'。查看更新后的答案。 – RedX

+0

感谢它的工作 –