Python Debugging Force Exception in VS Code

Viewed 24

I am using Visual Studio Code to debug a Python 3.6 application with remote debugging. I am trying to check whether exceptions are bubbled up to the logger.

When I set a breakpoint, how can I create an exception using the Debug Console, which will be caught by an except block?

try:
    print("Before Exception")
    print("Creating Exception Here")
except Exception:
    print("Exception Reached")

In this example, I would like to put a breakpoint on the second print statement and then create an exception, maybe ZeroDivisionError. I then want the third print statement (in the except block) to be reached.

Assume I am not able to modify the source code. (Otherwise, I would just add raise Exception() statements.) However, anything I can do in the debugger is fair game.

0 Answers
Related