We have to propagate exceptions from one node to another using RPC, using Thrift framework. I know that exceptions can be declared in Thrift like this:
exception SampleException {
1: optional string cause
}
And that generates an exception that extends the generic TException.
I want to create TException
s that have as a cause another exception that may not extend TException
, and to receive that in the other node. Is this possible?
If it's not possible then it would be nice to propagate generic exceptions that don't extend TException
. Bonus points if we can propagate RuntimeException
s.
I want to create TExceptions that have as a cause another exception, and to receive that in the other node. Is this possible?
exception bar {
1 : i32 nix
}
exception foo {
1 : bar bar
}
And that generates an exception that extends the generic TException.
Yes, that's the way it should be. That's not to say that TException
itself can't inherit from a RuntimeException
.
Also, it would be nice to have TExceptions that are RuntimeExceptions
Thrift is Open Source. You can have what you want. ;-) There is also this JIRA ticket
but it needs to be a TException also. Can it be a generic one?
You are bound to the base datatypes Thrift supports, and whatever complex types you create from it using struct, union, map<>, set<>, list<>, exception and typedef. If you need special behaviour then I recommend to serialize the data and raise the exception at the client side based on those data. Behind the scenes TException works just the same. If you think the current behaviour could improved, discuss on the mailing list and/or send a pull request.