Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 23rd, 2006, 6:58 PM   #1
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,888
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
try, except, finally ... where's noexcept?

I need something that will allow code encased in "try", to not be excepted by a specific error message.

The deprecated HTTP redirect in cherrypy raises an error called "cherrypy._cperror.HTTPRedirect", which messes up my debug decorator.

I need to be able to go:

try, noexcept cherrypy._cperror.HTTPRedirect:
    code1
except:
    code2

Where code2 will not be executed if an HTTPRedirect error occurs, but it will with any other error.

Any solutions? The obvious being not to use an external redirect.
Sane is offline   Reply With Quote
Old Feb 24th, 2006, 12:28 AM   #2
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 852
Rep Power: 4 The Dark is on a distinguished road
Do you want to trap the exception and not perform code2? I would think you would do something like:
try:
    code1
except cherrypy._cperror.HTTPRedirect:
    /* Do nothing*/
except:
    code2

or do you want to completely ignore the error and continue on with the rest of code1? In this case, you might have to have try ... except around each inidivual bit of code that might cause the exception (or put it in a function that has the try ... except in it).
The Dark is offline   Reply With Quote
Old Feb 24th, 2006, 5:40 AM   #3
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
HTTPRedirect is an exception that isn't an error. I can see why this would mess up your debug decorator, Sane; you want your decorator to log "normal" exceptions, but to ignore HTTPRedirect exceptions, because they need to be handled by CherryPy.

The solution is to catch the HTTPRedirect exception, and then to immediately raise it again:
try:
    code 1
except cherrypy._cperror.HTTPRedirect, e:
    raise cherrypy._cperror.HTTPRedirect, e
except:
    code 2
That should work.
Arevos is offline   Reply With Quote
Old Feb 24th, 2006, 4:44 PM   #4
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,888
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
OOhh! Raise it again! Gah! I should have thought of that... It's so obvious! Thanks!

This is what I had tried before
        try:
            return func(*args, **kwargs)
        except cherrypy._cperror.HTTPRedirect:
            pass
        except:
            return serveError(func.func_name, func.func_code, exc_info()[0], *args, **kwargs)
Which obviously didn't work.
Sane is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:20 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC