在当前状态下,Apache Thrift不支持继承,既不支持struct
/union
也不支持exception
。我的猜测是,这是因为有些语言在那里继承太复杂,不能实现,因为它不是语言的一部分。这在我脑海
一种解决方案是将异常转换成结构,只有一个例外,节俭和union
异常的数据转换成一个。客户端捕获“常见”异常并重新提出该包中的任何内容。
struct OverflowError {
1: double operator1
2: double operator2
3: string operation
}
struct DivByZeroError {
1: double numerator
}
union AllTheErrors {
1: OverflowError over
2: DivByZeroError div0
// more to come
}
exception MathError {
1: AllTheErrors theError
}
service ExceptionalCalculator {
double Add(1: double arg1, 2: double arg2) throws (1: MathError mex)
double Subtract(1: double arg1, 2: double arg2) throws (1: MathError mex)
double Divide(1: double arg1, 2: double arg2) throws (1: MathError mex)
double PriceOfDowJonesNextThursday() throws (1: MathError mex)
}
涉及相当多的工作,但可能是一个解决方案。
在有一个related discussion about protobuf,其可以是有帮助。