c# - 如何在asp.net中捕获COMException?

时间:2012-11-24 21:00:51

标签: c# asp.net exception sharepoint-2010 exception-handling

在我的sharepoint上的asp.net页面中,当我对数据库进行更改时,与其他用户同时,我收到此错误:

(11/24/2012 3:53:32 PM) - Error Message: Save Conflict.

Your changes conflict with those made concurrently by another user. If you want your changes to be applied, click Back in your Web browser, refresh the page, and resubmit your changes.
Stacktrace:    at Microsoft.SharePoint.SPGlobal.HandleComException(COMException comEx)
   at Microsoft.SharePoint.Library.SPRequest.UpdateField(String bstrUrl, String bstrListName, String bstrXML)
   at Microsoft.SharePoint.SPField.UpdateCore(Boolean bToggleSealed)
   at PDF_Library.VisualWebPart1.PDF_Library.import_sections_into_column()
   at PDF_Library.VisualWebPart1.PDF_Library.save_Click(Object sender, EventArgs e)

但是如何捕获此错误? 我试着做了

catch (COMException) {

}

但这不起作用......

有谁知道为什么?

1 个答案:

答案 0 :(得分:1)

COMException由HandleComException方法中的SharePoint处理。然后它抛出一个带有“Save Conflict”消息的Microsoft.SharePoint.SPException。如果您要捕获此特定异常类型,请将catch块更改为

catch (Microsoft.SharePoint.SPException) {
  // do stuff
}