This is an issue unique to go, because of go's duck typing interface system: There's no way to distinguish TException from other errors.
Currently TException is defined to be identical to error (link):
Which means when you try to do
It's always true.
TTransportException, TApplicationException, and TProtocolException are identifiable, but for exceptions generated from the compiler (that's defined in thrift files), TExecption is the only "common" type they share and it's very hard to write library code to handle them collectively.
My proposal is to add a new function to TException interface (which also need to be added to TTransportException, TApplicationException, TProtocolException, and all compiler generated exceptions). There are 2 ways to define this new function:
1. TExceptionType() TExceptionType, where TExceptionType is an enum type, with values of TTransportException, TApplicationException, TProtocolException, TIDLException (name tbd, open to suggestions, this is the one intended to be used by compiler)
2. TExceptionName() string, which for TTransportException the string would just be "TTransportException", etc. For compiler generated exceptions, I think the name should be the name of the exception with the thrift filename as the namespace. For example, for:
that's defined in my_service.thrift, the compiler generated name would be "my_service.MyError". Note that the namespace could be different from the actual go import namespace, as in if the thrift file have the line of "namespace go foo.bar.my_service_2", the go namespace would be "my_service_2" instead of "my_service"
I would slightly prefer the enum approach as it's simpler (there's no ambiguity on the namespace part of the string approach). Either way this requires compiler change to add the new function to generated exception types.