简体   繁体   中英

Python Debugging : Find where an exception is raised, go into debug mode?

Is there a command in the Python debugger (pdb) that says something like "run until the next exception is raised?"

Seems an obvious requirement but can't seem to find it.

Update : To be clear, my problem is an exception which is being caught and turned into an inadequate message in a log file. And I can't find where the exception is raised.

I figured that if I could go into trace mode and say "run until an exception is thrown" that would be the most straightforward way of finding it. I don't think post-mortem will work here.

Execute your script as follows:

python -m pdb myscript.py

Press c and Enter . When an uncaught exception is raised you program will stop running and fall back to the pdb debug prompt.

Can you search the code in the failing script for the text of the message that is logged (I realize that this may be difficult if the string is generated in a complex way). If you can find the point where the message is generated/logged then you can set an appropriate break point to troubleshoot the problem.

Unfortunately, AFAIK Python pdb debugging does not offer the capability that is present in some other languages to say, for example, break when Exception is raised .

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