简体   繁体   中英

why is try except block not working in visual studio code for python 3.7?

When implementing a try/except block, VS Code does not recognize the specified exception or any exception for that matter. Ex:

try:
    x = 1/0
except ZeroDivisionError:
    print("You cannot divide by zero ")

throws an exception error and does not print "You cannot divide by zero" when executed through the terminal. VS Code doesn't seem to be recognizing any exceptions. I've tried using the same code in IDLE and Sublime and it prints the correct message. Does anyone have any suggestions for fixing this?

Other information: I'm using the python extension from Microsoft and have no other extensions in VS Code.

Thanks!

This happens when you tick the Raised Exceptions option in Breakpoints section of the debug window panel on the left (once in the debug mode). See the screenshot here in the related GitHub issue .

Untick this option and you will have your expected behavior. The behavior you describe is intended when that option is ticked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM