使用 Detail 属性处理特定错误
为了进一步对异常进行分类,Reporting Services 返回 SOAP 异常详细信息属性中子元素的 InnerText 属性中的其他错误信息。 因为该 Detail 属性是 XmlNode 对象,所以,可以使用以下代码访问 Message 子元素的内部文本。
有关在 Detail 属性中包含的所有可用子元素的列表,请参阅 Detail 属性。 有关详细信息,请参阅 Microsoft .NET Framework SDK 文档中的“Detail 属性”。
Try
' Code for accessing the report server
Catch ex As SoapException
' The exception is a SOAP exception, so use
' the Detail property's Message element.
Console.WriteLine(ex.Detail("Message").InnerXml)
End Try
try
{
// Code for accessing the report server
}
catch (SoapException ex)
{
// The exception is a SOAP exception, so use
// the Detail property's Message element.
Console.WriteLine(ex.Detail["Message"].InnerXml);
}
Try
' Code for accessing the report server
Catch ex As SoapException
If ex.Detail("ErrorCode").InnerXml = "rsInvalidItemName" Then
End If ' Perform an action based on the specific error code
End Try
try
{
// Code for accessing the report server
}
catch (SoapException ex)
{
if (ex.Detail["ErrorCode"].InnerXml == "rsInvalidItemName")
{
// Perform an action based on the specific error code
}
}
下面的代码行将在 SOAP 异常中返回的特定错误代码写入控制台。 您还可以对错误代码进行评估并执行特定操作。
Console.WriteLine(ex.Detail("ErrorCode").InnerXml)
Console.WriteLine(ex.Detail["ErrorCode"].InnerXml);