thrift-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ben Craig <ben.cr...@ni.com>
Subject Re: Thrift custom exceptions C++
Date Mon, 17 Feb 2014 15:03:02 GMT
The custom exceptions don't modify message_.  They do transfer user 
defined state across the RPC boundary though.  For example...

// example.thrift

exception MyException
{
  1: i32 error_code
}
service MyService
{
   void do_something() throw(1: MyException the_exception)
}

// server
void MyService::do_something(){
   MyException exception;
   exception.error_code = 42;
   throw exception;
}

//client
try {
   my_client_obj.do_something();
} catch (const MyException &e) {
   std::cout<<e.error_code; //should print 42
}


Ronald van Gorkum <ronald.vangorkum@trust2core.de> wrote on 02/17/2014 
02:17:32 AM:

> From: Ronald van Gorkum <ronald.vangorkum@trust2core.de>
> To: thriftuser <user@thrift.apache.org>, 
> Date: 02/17/2014 02:18 AM
> Subject: Thrift custom exceptions C++
> 
> Hi all,
> 
> I defined some custom exceptions in the Thrift IDL. From this IDL I 
> generated C++ code. In the generated code the parent class (TException) 
> is inherited, but the constructor isn't called. When I receive an 
> exception I'm always receiving the default exception class instead of 
> the desired custom exception class. If I look into the sources the 
> parent class variable message_ is only set when the constructor of that 
> class is being called with the name of the custom exception (what is not 

> done in the generated code). Or, because the variable is protected, the 
> content is changed by the custom exception class, but also therefore is 
> no method generated. Who has also experiences with custom exceptions and 

> raise them in C++ code and has a proper solution? Or is this a Thrift 
> generator bug?
> 
> Thanks.
> 
> Ronald


Mime
View raw message