473,322 Members | 1,401 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,322 software developers and data experts.

Catch occasional exceptions - curses

Hello

I'm almost done with my webcrawler with a nice curses interface. But every
once in a while an exception is thrown and not caught, and because of the
use of curses I can't figure out which exceptions are thrown and from
where.

Is the a way to catch all exceptions not handled elsewhere and print them
to my log window? IE. something like:

if __name__ == 'main':
try:
# the whole program (more or less)
except CatchAllExceptionsInSomeMagicWay:
printExceptionToLog()

--
Regards
/Thomas

Jul 18 '05 #1
3 1786
Thomas Lindgaard wrote:
Hello

I'm almost done with my webcrawler with a nice curses interface. But every
once in a while an exception is thrown and not caught, and because of the
use of curses I can't figure out which exceptions are thrown and from
where.

Is the a way to catch all exceptions not handled elsewhere and print them
to my log window? IE. something like:

if __name__ == 'main':
try:
# the whole program (more or less)
except CatchAllExceptionsInSomeMagicWay:
printExceptionToLog()


try:
#
except:
traceback.print_exc(sys.exc_info())

Variations on that using other functions in the traceback
module are easy...
Jul 18 '05 #2
On Wed, 28 Jul 2004 18:37:31 -0400, Peter Hansen wrote:
try:
#
except:
traceback.print_exc(sys.exc_info())

Variations on that using other functions in the traceback
module are easy...


OK - I've wrapped most of my main function and run the crawler... but it
hasn't thrown an exception yet, so I don't know if it does the job. But
thanks :)

--
Regards
/Thomas

Jul 18 '05 #3
I've found there is another easy way of doing this. Use sys.excepthook

def errorHandler():
# do error handingl
# this will catch all leftover excptions

sys.excepthook = errorHandler

this way you don't have to wrap the whole program in a tr/except

-Josh

On Thu, 29 Jul 2004 23:22:58 +0200, Thomas Lindgaard
<th****@it-snedkeren.black_hole.dk> wrote:
On Wed, 28 Jul 2004 18:37:31 -0400, Peter Hansen wrote:
try:
#
except:
traceback.print_exc(sys.exc_info())

Variations on that using other functions in the traceback
module are easy...


OK - I've wrapped most of my main function and run the crawler... but it
hasn't thrown an exception yet, so I don't know if it does the job. But
thanks :)

--
Regards
/Thomas

--
http://mail.python.org/mailman/listinfo/python-list

Jul 18 '05 #4

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

Similar topics

24
by: Steven T. Hatton | last post by:
If I understand correctly, I have no assurance that I can determine the type of a simple class instance thrown as an exception unless I explicitly catch it by name. (non-derived classes having no...
8
by: Z D | last post by:
Hi, I was wondering what's the point of "finally" is in a try..catch..finally block? Isn't it the same to put the code that would be in the "finally" section right after the try/catch block?...
9
by: Steven Blair | last post by:
Hi, I need to catch exceotions on File.Delete() After checking the help, I have noticed that thgere are serevral Exceptions that can be thrown. My question is, should I catch all thes...
13
by: Benny | last post by:
Hi, I have something like this: try { // some code } catch // note - i am catching everything now {
23
by: VB Programmer | last post by:
Variable scope doesn't make sense to me when it comes to Try Catch Finally. Example: In order to close/dispose a db connection you have to dim the connection outside of the Try Catch Finally...
9
by: Bob Achgill | last post by:
I really like this function but have tried to slow down on using it because I get a 1 second pause each time I use it. I don't really understand why the computer has to think for 1 second! ...
32
by: cj | last post by:
Another wish of mine. I wish there was a way in the Try Catch structure to say if there wasn't an error to do something. Like an else statement. Try Catch Else Finally. Also because I...
5
by: Alan Silver | last post by:
Hello, One of my web sites seems to throw the occasional exception in a place where I don't expect it. I know I should expect them anywhere, but just supposing I've missed one, is there a way of...
23
by: pigeonrandle | last post by:
Hi, Does this bit of code represent complete overkill?! try { //create a treenode TreeNode tn = new TreeNode(); //add it to a treeview tv.Nodes.Add(tn);
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.