Normally you handle each exception case separately because they mean something different and require different actions. A transport or protocol exception may require you to close and reconnect; whereas the application exception is a command level exception which you need to handle. If looks like you are using C++ from the syntax I believe you could do what you are looking for with RTTI, but I would recommend using separate blocks... the code is more understandable and maintainable that way.
I'm not sure about the C++ runtime, but on the C# runtime the TTransportException only carries a string. In my experience so far a TTransportException always means that the connection closed, or a new one failed to open. It would be nice to pack the socket error number into the TTransportException on all platforms. Of course if you really want a GetType() function on TException then you do have access to the source code and can make those modifications for your environment. James E. King, III Senior Software Engineer Dell (EqualLogic) HIT Team (ASM) -----Original Message----- From: thrift thrift [mailto:[email protected]] Sent: Friday, June 04, 2010 3:04 AM To: [email protected] Subject: About TException Hi, All, I have a problem about TException. In sample code, we can catch execption as try{ ... } catch (TException &tx) { tx.what() } but the problem is that TException do not have GetType() funciton, so we can not know what kind of execption is occured. It can be TApplicationException, TProtocolException, TTransportException, etc. And also in each kind of execption, there is different sub-type in it. (NOT_OPEN, ALREADY_OPEN, TIMED_OUT, etc.) I found that we can do it seperately as try { transport->open(); } catch (TTransportException& ttx) { printf("Connect failed: %s\n", ttx.what()); } try { printf("testVoid()"); testClient.testVoid(); printf(" = void\n"); } catch (TApplicationException tax) { printf("%s\n", tax.what()); } but Is there some better way that we can handle all kinds of execptions in one try-catch and get exact execption type and execption sub type? Anyone has good ideas about it? Thanks very much. Best Regards,
