[問題] exception

看板Python作者 (allstar)時間15年前 (2009/10/02 00:29), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/1
使用 Tkinter 當 UI 時,該如何讓未處理的 exception 能停止整個程式呢? 以底下這個程式為例子來說: from Tkinter import * def raiseException(): raise Exception('unhandled exception') root = Tk() Button(root, text = 'Button', command = raiseException).pack() root.mainloop() 使用者按下按鈕後,會產生一個沒人處理的 exception 在 C++,這會導致整個程式崩潰掉 可是在使用 Tkinter 的 python 程式裡,只會在 console 冒出錯誤訊息 程式還是活的好好的 請問要怎樣修改才能讓程式像 C++ 一樣崩潰掉? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.170.57.216

10/02 00:49, , 1F
自己找到了,把 root.report_callback_exception 改掉就行了
10/02 00:49, 1F
文章代碼(AID): #1AnDZcZg (Python)
文章代碼(AID): #1AnDZcZg (Python)