#!/usr/bin/pythonfilename='hello'#try except finally demotry: open('abc.txt') PRint helloexcept IOError,msg: print 'the file not exist'except NameError,msg: print 'hello not defined'finally: print 'end'#throw exceptionif filename == "hello": raise TypeError('nothing')
1、AssertionError:assert語句失敗
2、AttributeError:試圖訪問一個對象沒有的屬性
3、IOError:輸入輸出異常,基本是無法打開文件
4、ImportError:無法引入模塊或者包,基本是路徑問題
5、IndentationError:語法錯誤,代碼沒有正確對齊
6、IndexError:下標索引超出序列邊界
7、KeyError:試圖訪問你字典里不存在的鍵
8、KeyboardInterrupt:Ctrl+C被按下
9、NameError:使用一個還聲明的變量
10、SyntaxError:代碼邏輯語法出錯,不能執行
12、TypeError:傳入的對象類型與要求不符
13、UnboundLocalError:試圖問一個還未設置的全局變量,基本上是由于另有一個同名的全局變量
14、ValueError:傳入一個不被期望的值,即使類型正確
新聞熱點
疑難解答