處理未造成例外狀況的警告與案例
Reporting Services 不會擲回警告與某些錯誤的例外狀況。例如,當您使用 CreateReport 方法來將新報表發行到報表伺服器時,會以 Warning 物件的陣列傳回發生的任何警告。應該處理和顯示這些警告,才能採取適當的動作。
Try
warnings = rs.CreateReport(name, parentFolder, False, definition, Nothing)
If Not (warnings Is Nothing) 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
{
warnings = rs.CreateReport(name, parentFolder, false, definition, null);
if (warnings != null)
{
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 陣列。您應該評估陣列、檢查 null,而且如果找不到項目,應該讓使用者知道。