473,415 Members | 1,562 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,415 software developers and data experts.

handling unexpected exceptions in pdb

Hi all,

I'm in an interactive session in pdb, debugging my code using
pdb.runcall. Somewhere, an exception is raised and lands uncaught on
stdout. Is there any way of picking up this exception and at least
read the full message, or even accessing its stack trace to determine
where exactly within the one line I just executed it was raised? This
is where I'm stuck:
/usr/local/apache2/bin/Model/Database.py(287)disconnect()
(Pdb) n
FlushError: FlushErr...perly.",)
/usr/local/apache2/bin/Model/Database.py(287)disconnect()
(Pdb) import sys
(Pdb) sys.last_traceback
*** AttributeError: 'module' object has no attribute 'last_traceback'

Thanks, Simon

Jul 10 '08 #1
2 3411
Simon Bierbaum <bi******@vierfalt.comwrites:
Hi all,

I'm in an interactive session in pdb, debugging my code using
pdb.runcall. Somewhere, an exception is raised and lands uncaught on
stdout. Is there any way of picking up this exception and at least
read the full message, or even accessing its stack trace to determine
where exactly within the one line I just executed it was raised? This
is where I'm stuck:
>/usr/local/apache2/bin/Model/Database.py(287)disconnect()
(Pdb) n
FlushError: FlushErr...perly.",)
>/usr/local/apache2/bin/Model/Database.py(287)disconnect()
(Pdb) import sys
(Pdb) sys.last_traceback
*** AttributeError: 'module' object has no attribute 'last_traceback'

Thanks, Simon
I think basically you want runcall to be wrapped in a try block. So in pdb.py
instead of:

def runcall(*args, **kwds):
return Pdb().runcall(*args, **kwds)
Change with:

def runcall(*args, **kwds):
p=Pdb()
try:
return p.runcall(*args, **kwds)
except:
traceback.print_exc()
print "Uncaught exception. Entering post mortem debugging"
t = sys.exc_info()[2]
p.interaction(t.tb_frame,t)
print "Post mortem debugger finished."
return None

Code like this appears near the bottom of the pdb.py file. If that
works, you may want to file a bug Python report to change pdb. Also
note that one may want to do the same thing on run() and runeval()

But also if this does what you want, please file a feature request to pydb:
http://sourceforge.net/tracker/?func...95&atid=497162

and I'll probably make it happen in the next release.

This is the first time I've heard of anyone using runcall.

Jul 10 '08 #2

Am 10.07.2008 um 20:52 schrieb R. Bernstein:
Simon Bierbaum <bi******@vierfalt.comwrites:
>Hi all,

I'm in an interactive session in pdb, debugging my code using
pdb.runcall. Somewhere, an exception is raised and lands uncaught on
stdout. Is there any way of picking up this exception and at least
read the full message, or even accessing its stack trace to determine
where exactly within the one line I just executed it was raised? This
is where I'm stuck:
>>/usr/local/apache2/bin/Model/Database.py(287)disconnect()
(Pdb) n
FlushError: FlushErr...perly.",)
>>/usr/local/apache2/bin/Model/Database.py(287)disconnect()
(Pdb) import sys
(Pdb) sys.last_traceback
*** AttributeError: 'module' object has no attribute 'last_traceback'

Thanks, Simon

I think basically you want runcall to be wrapped in a try block. So
in pdb.py
instead of:

def runcall(*args, **kwds):
return Pdb().runcall(*args, **kwds)
Change with:

def runcall(*args, **kwds):
p=Pdb()
try:
return p.runcall(*args, **kwds)
except:
traceback.print_exc()
print "Uncaught exception. Entering post mortem debugging"
t = sys.exc_info()[2]
p.interaction(t.tb_frame,t)
print "Post mortem debugger finished."
return None

Code like this appears near the bottom of the pdb.py file. If that
works, you may want to file a bug Python report to change pdb. Also
note that one may want to do the same thing on run() and runeval()

But also if this does what you want, please file a feature request
to pydb:
http://sourceforge.net/tracker/?func...95&atid=497162

and I'll probably make it happen in the next release.

This is the first time I've heard of anyone using runcall.
My app is called from mod_python with the PythonEnablePdb option set
to On, which makes mod_python call my handler function not directly,
but wrapped into a pdb.runcall(). I figure I might not be the first
one to use runcall under these circumstances ;-)

I'll definitely give your hack a try, thank you for your help!

Cheers, Simon
Jul 10 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Hans-Joachim Widmaier | last post by:
Hi all. Handling files is an extremely frequent task in programming, so most programming languages have an abstraction of the basic files offered by the underlying operating system. This is...
12
by: Ritz, Bruno | last post by:
hi in java i found that when a method has a throws clause in the definition, callers must either handle the exceptions thrown by the method they are calling or "forward" the exception to the...
34
by: rawCoder | last post by:
I have read that Exception Handling is expensive performance wise ( other than Throw ) , but exactly how ? Please consider the following example ... ////////////////// Code Block 1...
5
by: Bevo | last post by:
In my enterprise application I'd like my DataAccess layer to be responsible for handling all database error situations and to basically throw custom exceptions according to whether db connection is...
5
by: Lau Lei Cheong | last post by:
Hello, I'm currently using Application_Error method in Global.asax.cs to handle errors. Recently, I heard about Page.ErrorPage and plan to use it for handling errors on certain pages. Are...
15
by: bill salkin | last post by:
I'd like to create a custom error handler like this in VB.NET: .... try ... Throw ("Lender Name not in table") .... catch ("Lender Name not in table")
4
by: Al Williams | last post by:
Hi, I have error handling in place throughout my application. I also start the application wrapped in error handling code to catch any unexpected exceptions (i.e. exceptions that occur where I...
9
by: Gustaf | last post by:
I'm confused about structured error handling. The following piece of code is a simplification of a class library I'm working on. It works, and it does what I want, but I'm still not convinced that...
2
by: Petr Jakes | last post by:
I am a little bit confused by all possibilities for exceptions handling in Python (probably because I am not skilled enough??) I did try to search trough this list and reading Python tutorial about...
35
by: eliben | last post by:
Python provides a quite good and feature-complete exception handling mechanism for its programmers. This is good. But exceptions, like any complex construct, are difficult to use correctly,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.