I catch a FaultException
while calling a service API, e.g.
catch(FaultException<MyCustomEx> e)
{
// How do I get the MyCustomEx object here?
}
I want to call some method on the MyCustomEx
object embedded inside.
e.getTheActualExc().getMyCustomErrorCode();
How do I get the actual object?
According to
http://msdn.microsoft.com/ru-ru/library/ms576199(v=vs.110).aspx
The required property is Detail
:
try {
...
}
catch(FaultException<MyCustomEx> e) {
MyCustomEx detail = e.Detail;
...
}
Or, if you have to catch FaultException
class, you can use Reflection:
try {
...
}
catch (FaultException e) {
PropertyInfo pi = e.GetType().GetProperty("Detail");
if (pi != null) {
Object rawDetail = pi.GetValue(e);
MyCustomEx detail = rawDetail as MyCustomEx;
if (detail != null) {
...
}
...
}
...
}
the e.Detail property will give you the object of the FaultException<> , see MSDN.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With