I believe the reason this fails may be because of how you're using the 
comma-notation to pass the arg to the constructor.

There were some recent changes to the Thrift Python generator -- can you paste 
the generated code for class NotValidException that you're using?

If it looks like this:

class NotValidException(Exception):
  def __init__(self, d=None):
    if isinstance(d, dict):
...
  
Then the issue is that you're passing a string as args, and it's not actually 
turning into the "why" field in your exception when your __init__ method is 
invoked.

If you're using the latest update to the generator, then this SHOULD work, but 
you'll still be better off doing:

raise NotValidException(why="thisiswhy")

-----Original Message-----
From: Phillip B Oldham [mailto:[email protected]] 
Sent: Tuesday, January 20, 2009 2:43 PM
To: [email protected]
Subject: Re: Empty exceptions with python server/client.

On Tue, Jan 20, 2009 at 10:24 PM, Mark Slee <[email protected]> wrote:
> Can you paste your code that raises the exception?

The thrift file:

exception NotValidException {
  string why
}

service TestService {
  bool isValid( 1:string text ) throws ( 1:NotValidException e ) }

the python server class:

class TestServiceHandler:
  def isValid(self, text):
    raise NotValidException, "because it isn't"
    return False

the python client:

try:
  try:
    client.isValid("test")
  catch NotValidException, e
    print e.why
except Thrift.TException, tx:
  print 'Error: %s' % (tx.message)

I've tried calling the exception attribute "message", I've tried various 
variations on the theme laid out above, but when the exception gets properly 
caught by either of the except blocks the message returned is None.

> Is this an exception being thrown across an RPC call at the application level?

I'm not sure I understand the question, but you will hopefully see from above 
what I'm trying to do.

--
Phillip B Oldham
[email protected]
+44 (0) 7525 01 09 01

Reply via email to