本文介绍了如何在类型为异常的对象上使用SoapException方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个方法获取类型的参数 - 异常 WriteException(Exception ex,int index,string s)
{
//我的代码在这里...
}
有时候,该方法会在每次exeption时获得一个异常
对象,有时 SoapException
是实物 SoapException
我想要打印: ex.Detail.InnerText
但如果 ex
的类型为异常
。
所以在我识别类型后,我该怎么办? c $ c> SoapException ex.Detail.InnerText ?
解决方案
WriteException(Exception ex,int index,string s)
{
var soapEx = ex as SoapException;
if(null!= soapEx)
{
Console.WriteLine(soapEx.Detail.InnerText);
返回;
}
Console.WriteLine(ex.Message);
}
另一种可能的解决方案使用动态
关键字:
WriteException(Exception ex,int index,string s)
{
dynamic soapEx = ex;
Console.WriteLine(soapEx.Detail.InnerText);
Console.WriteLine(ex.Message);
}
I have a Method that get paramater of type - Exception
WriteException(Exception ex, int index, string s)
{
// my code here...
}
sometimes the method gets an Exception
object and sometimes SoapException
every time the exeption is of kind SoapException
I want print: ex.Detail.InnerText
but if ex
is of type Exception
.
so after I recognize the type, how can I do SoapException ex.Detail.InnerText
?
解决方案
WriteException(Exception ex, int index, string s)
{
var soapEx = ex as SoapException;
if(null != soapEx)
{
Console.WriteLine(soapEx.Detail.InnerText);
return;
}
Console.WriteLine(ex.Message);
}
another possible solution uses the dynamic
keyword:
WriteException(Exception ex, int index, string s)
{
dynamic soapEx = ex;
Console.WriteLine(soapEx.Detail.InnerText);
Console.WriteLine(ex.Message);
}
这篇关于如何在类型为异常的对象上使用SoapException方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!