2016-09-16 96 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

感謝它的工作 –