2015-09-06 58 views
2

我有Python工具的Visual Studio 2015,我試圖調試一個python應用程序,但它不會中斷某個錯誤。Python(視覺工作室)中斷的錯誤

的錯誤是一個IndexError,可使用此代碼被複制:

matrix = [5, 6, 7] 
print matrix[2] 
print matrix[5000] 

運行,將讓我在控制檯的消息,但它不會自動斷。 Console message

在另一方面,如果我有一個NameError:

nonExistingFunction() 

它不破發,讓我很容易地看到它錯了... It can break the code apparently

這是正常的嗎?有沒有一種方法可以讓視覺工作室在發生像IndexError這樣的錯誤時中斷?

這裏的選項窗口(這實際上適用於蟒蛇不知道)和Python工具的截圖>調試

My settings for debugging, if that helps My settings for python tools > debugging

回答

4

看看PVTS中的文檔類別exceptions

If an error occurs while your program is being debugged, and you don't have an exception handler for it, the debugger will break and show you the error.

enter image description here

的一段後,他們說:

If you are being interrupted often by the debugger breaking on exceptions, or if the debugger is not breaking on some exceptions that you would like it to break on, you can modify the settings in the Exceptions window. On the Debug menu, click Exceptions, and expand the Python Exceptions entry. Here you can see all the exceptions that are already know and can be configured.

對於Visual Studio 2017年,

The Debug > Windows > Exception Settings menu command brings up a window in which you can expand Python Exceptions:

enter image description here

+2

我從來沒有使用過該窗口,並它總是在那裏...我想這是視覺工作室,如此充滿特色,以至於你永遠無法用新的東西去學習。謝謝。我會盡快接受你的回答(顯然你有多少時間才能接受答案)。 – user886079