Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Defining an error handler for a particular exception
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Expand all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Alberto  
View profile  
 More options Feb 23 2006, 8:29 am
From: "Alberto" <albe...@toscat.net>
Date: Thu, 23 Feb 2006 05:29:33 -0800
Local: Thurs, Feb 23 2006 8:29 am
Subject: Defining an error handler for a particular exception
Hi,

I've just started playing with the new error handling mechanisms
recently introduced (which BTW look great :)

I have a, probably dumb, question:

How can I set a decorator for a method which redirects to another when
a particular exception occurs?

That is:

@error_handler(if exception is Y branch to method X)
def method:
    # some code that could raise Y

def X:
    # do something with the exception

I implicitly believed this could be done from skimming the
error_handling thread a couple of weeks ago but I can't seem to  find
the post where (i believe) it said it or how to do it.

TIA,
Alberto


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alberto  
View profile  
 More options Feb 23 2006, 8:52 am
From: "Alberto" <albe...@toscat.net>
Date: Thu, 23 Feb 2006 05:52:58 -0800
Local: Thurs, Feb 23 2006 8:52 am
Subject: Re: Defining an error handler for a particular exception
Duh, shhould have read the errorhadling wiki before posting...

Ive managed to do it like:

class Root(controllers.RootController):
    @turbogears.expose()
    def error(self):
        return "An error ocured"

    @turbogears.expose()
    @turbogears.controllers.exception_handler(error, "ValueError")
    def index(self):
        raise ValueError

BTW, Shouldn't exception_handler be imported at turbogears/__init__ too
like error_handler is, just for convenience...

Regards,
 Alberto


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Simon Belak  
View profile  
 More options Feb 23 2006, 10:02 am
From: Simon Belak <simon.be...@hruska.si>
Date: Thu, 23 Feb 2006 16:02:03 +0100
Local: Thurs, Feb 23 2006 10:02 am
Subject: Re: [TurboGears] Re: Defining an error handler for a particular exception

Alberto wrote:
> Duh, shhould have read the errorhadling wiki before posting...

> Ive managed to do it like:

> class Root(controllers.RootController):
>     @turbogears.expose()
>     def error(self):
>         return "An error ocured"

>     @turbogears.expose()
>     @turbogears.controllers.exception_handler(error, "ValueError")
>     def index(self):
>         raise ValueError

Are you sure, this works as expecetd?

Perhaps

   "isinstance(tg_exceptions, ValueError)"

will serve you better.

> BTW, Shouldn't exception_handler be imported at turbogears/__init__ too
> like error_handler is, just for convenience...

Yes it should be (and is). Which version are you using?

Cheers,
Simon


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alberto  
View profile  
 More options Feb 23 2006, 10:26 am
From: "Alberto" <albe...@toscat.net>
Date: Thu, 23 Feb 2006 07:26:08 -0800
Local: Thurs, Feb 23 2006 10:26 am
Subject: Re: Defining an error handler for a particular exception
Actually I was just wondering why it didn't work as expected... :) It
first seemed so, but it was handling ALL exceptions... I'm going to try
your example...

Thanks for the help!

Alberto

P.S: Using r825, i've locally patched my turbogears/__init__.py with:
exception_handler = controllers.exception_handler
and works for me


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Simon Belak  
View profile  
 More options Feb 23 2006, 10:38 am
From: Simon Belak <simon.be...@hruska.si>
Date: Thu, 23 Feb 2006 16:38:46 +0100
Local: Thurs, Feb 23 2006 10:38 am
Subject: Re: [TurboGears] Re: Defining an error handler for a particular exception
Alberto wrote:

  > P.S: Using r825, i've locally patched my turbogears/__init__.py with:

> exception_handler = controllers.exception_handler
> and works for me

I am such an idiot! Of curse, the line above is missing. Thanks!

Cheers,
Simon


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alberto  
View profile  
 More options Feb 23 2006, 10:39 am
From: "Alberto" <albe...@toscat.net>
Date: Thu, 23 Feb 2006 07:39:13 -0800
Local: Thurs, Feb 23 2006 10:39 am
Subject: Re: Defining an error handler for a particular exception
Works like a charm now... Thanks

P.S.

Are you sure it was imported?? I'm looking through the rev. log and
can't seem to find it...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »