473,795 Members | 3,006 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

handling uncaught exceptions with pdb?

I think I've asked about this before, but is there a way to set up
Python to handle uncaught exceptions with pdb? I know about setting
sys.except_hook to something that calls pdb, but this is normally done
at the outer level of a program, and by the time that hook gets
called, the exception has already unwound the stack to the outermost
level. My situation is I run a multi-hour or multi-day computation
that eventually crashes due to some unexpected input and I'd like to
break to the debugger at the innermost level, right when the exception
is encountered, so I can fix the error with pdb commands and resume
processing. Of course this presumes a certain semantics for Python
exceptions (i.e. handling one involves scanning the stack twice, once
to look for a handler and again to actually unwind the stack) and I'm
not sure if it's really done that way. I do know that Lisp has a
requirement like that, though; so maybe there is hope.
Sep 10 '08 #1
5 2241
Paul Rubin <http://ph****@NOSPAM.i nvalidwrites:
I think I've asked about this before, but is there a way to set up
Python to handle uncaught exceptions with pdb? I know about setting
sys.except_hook to something that calls pdb, but this is normally done
at the outer level of a program, and by the time that hook gets
called, the exception has already unwound the stack to the outermost
level. My situation is I run a multi-hour or multi-day computation
that eventually crashes due to some unexpected input and I'd like to
break to the debugger at the innermost level, right when the exception
is encountered, so I can fix the error with pdb commands and resume
processing.
....

Why not use the traceback you get to show you where to change the code
around that point to add an exception handler there which calls the
debugger?
Sep 12 '08 #2
R. Bernstein schrieb:
Paul Rubin <http://ph****@NOSPAM.i nvalidwrites:
>I think I've asked about this before, but is there a way to set up
Python to handle uncaught exceptions with pdb? I know about setting
sys.except_hoo k to something that calls pdb, but this is normally done
at the outer level of a program, and by the time that hook gets
called, the exception has already unwound the stack to the outermost
level. My situation is I run a multi-hour or multi-day computation
that eventually crashes due to some unexpected input and I'd like to
break to the debugger at the innermost level, right when the exception
is encountered, so I can fix the error with pdb commands and resume
processing.
...

Why not use the traceback you get to show you where to change the code
around that point to add an exception handler there which calls the
debugger?
Because he wants to fix the issue directly in-place, and then continue,
instead of losing hours or even days of computation.

However, it's not possible AFAIK.

Diez
Sep 12 '08 #3
Paul Rubin schrieb:
I think I've asked about this before, but is there a way to set up
Python to handle uncaught exceptions with pdb? I know about setting
sys.except_hook to something that calls pdb, but this is normally done
at the outer level of a program, and by the time that hook gets
called, the exception has already unwound the stack to the outermost
level. My situation is I run a multi-hour or multi-day computation
that eventually crashes due to some unexpected input and I'd like to
break to the debugger at the innermost level, right when the exception
is encountered, so I can fix the error with pdb commands and resume
processing. Of course this presumes a certain semantics for Python
exceptions (i.e. handling one involves scanning the stack twice, once
to look for a handler and again to actually unwind the stack) and I'm
not sure if it's really done that way. I do know that Lisp has a
requirement like that, though; so maybe there is hope.
Would this work (although it probably will slow down the program)?

<snip>
import sys, pdb

def tracefunc(frame , event, arg):
if event == "exception" :
pdb.set_trace()
return tracefunc

sys.settrace(tr acefunc)

def test(arg):
if arg 20:
raise ValueError(arg)
return test(arg+1)

test(0)
<snip>

Thomas
Sep 12 '08 #4
"Diez B. Roggisch" <de***@nospam.w eb.dewrites:
R. Bernstein schrieb:
>Paul Rubin <http://ph****@NOSPAM.i nvalidwrites:
>>I think I've asked about this before, but is there a way to set up
Python to handle uncaught exceptions with pdb? I know about setting
sys.except_ho ok to something that calls pdb, but this is normally done
at the outer level of a program, and by the time that hook gets
called, the exception has already unwound the stack to the outermost
level. My situation is I run a multi-hour or multi-day computation
that eventually crashes due to some unexpected input and I'd like to
break to the debugger at the innermost level, right when the exception
is encountered, so I can fix the error with pdb commands and resume
processing.
...

Why not use the traceback you get to show you where to change the code
around that point to add an exception handler there which calls the
debugger?

Because he wants to fix the issue directly in-place, and then
continue, instead of losing hours or even days of computation.
Then proactively add exception handlers ;-)
Sep 12 '08 #5
2008/9/10 Paul Rubin <"http://phr.cx"@nospam. invalid>:
I think I've asked about this before, but is there a way to set up
Python to handle uncaught exceptions with pdb?
http://code.activestate.com/recipes/65287/

--
Cheers,
Simon B.
si***@brunningo nline.net
http://www.brunningonline.net/simon/blog/
GTalk: simon.brunning | MSN: small_values | Yahoo: smallvalues | Twitter: brunns
Sep 12 '08 #6

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

Similar topics

0
1220
by: Jeremy Fincher | last post by:
I've just converted my application to use the logging module for its logging needs (it's quite excellent, actually :)). One thing I still have to resolve, though: in many places in my application, I want to catch *all* exceptions *except*, for instance, KeyboardInterrupt and SystemExit. So I'll have code like this: try: callback(data) except Exception, e: log.exception("Uncaught exception from callback")
3
4521
by: Ross | last post by:
Hi, I have a message box that displays the message "Unhandled exception in Cash32.exe: 0xC000005: access violation". Is there anyway to write an exception that handles this message. For example class microsoft_errors{};
9
5005
by: David B | last post by:
Why is it so difficult to report bugs to Microsoft? I have a documented bug and an small test example. I don't really see why I should have to pay to tell them about it... Anyway, the following code exhibits the bug. If it is built and run from Visual Studio.NET 2003 in debug mode it works correctly as expected. However, if built in Release mode it fails with an "uncaught exception" error, although the exception does have a valid...
11
5600
by: chopsnsauce | last post by:
Here's the example: Dim frm As New FORM1 Try frm.show Catch ex As Exception msgbox ex.message
0
9673
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9522
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10448
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9046
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7544
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6784
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5566
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2922
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.