![]() |
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: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. |
Do you want to trap the exception and not perform code2? I would think you would do something like:
:
try: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). |
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: |
OOhh! Raise it again! Gah! I should have thought of that... It's so obvious! Thanks!
This is what I had tried before :
try: |
| All times are GMT -5. The time now is 9:14 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC