处理不导致异常的警告和事例
对于警告和某些错误,Reporting Services 不引发异常。例如,在您使用 CreateCatalogItem 方法以便将新的报表发布到报表服务器时,出现的任何警告都将以 Warning 对象的数组形式返回。应处理和显示这些警告,以便采取相应操作。
Try
rs.CreateCatalogItem(name, parentFolder, False, definition, Nothing, warnings)
If Not (warnings.Length = 0) Then
Dim warning As Warning
For Each warning In warnings
Console.WriteLine(warning.Message)
Next warning
Else
Console.WriteLine("Report {0} created successfully with no warnings", name)
End If
Catch ex As SoapException
Console.WriteLine(ex.Detail("Message").InnerXml)
End Try
try
{
rs.CreateCatalogItem("Report", name, parentFolder, false, definition, null, out warnings);
if (warnings.Length != 0)
{
foreach (Warning warning in warnings)
{
Console.WriteLine(warning.Message);
}
}
else
Console.WriteLine("Report {0} created successfully with no warnings", name);
}
catch (SoapException ex)
{
Console.WriteLine(ex.Detail["Message"].InnerXml);
}
处理错误的另一个方法是评估某些方法的返回值。例如,FindItems 方法可用于搜索报表服务器数据库中的特定项。如果未找到匹配搜索条件的项,则返回空的 CatalogItem 对象的数组。您应该对该数组进行评估、检查 null 并让用户知道未找到任何项。