Note that there are some explanatory texts on larger screens.

plurals
  1. POSharePoint WebPart Catching error caused by webControls
    text
    copied!<p>I am creating a SharePoint WebPart which uses GridView and ObjectDataSource for retrieving data. When the connection is terminated (for different reasons) I want to catch exception and redirect user to page with information. I do not know if my WebPart will be placed in other WebParts or directly on a page.</p> <p>I simulate the error by throwing Exception in the Select method of my class bounded to ObjectDataSource:</p> <pre><code>public List&lt;Item&gt; getItems(String param, int maximumRows, int startRowIndex) { if (param == "a") throw new Exception("exception"); </code></pre> <p>I can catch Exception whenever I invoke data binding in my code (example):</p> <pre><code>try { gvMain.PageIndex = 0; //gvMian - SPGridView gvMain.DataBind(); } catch (Exception ex) { Page.Cache["cacheError"] = ex.Message; SPUtility.Redirect(SPUtility.GetPageUrlPath(HttpContext.Current) + "?wnd=err", SPRedirectFlags.Trusted, HttpContext.Current); } </code></pre> <p>but sometimes the page cannot catch exception (probably the data binding is invoked automatically) and shows server error with stack trace:</p> <pre><code>[Exception: exception] MyProject.odsClass.getItems(String param, Int32 maximumRows, Int32 startRowIndex) +211 [TargetInvocationException: Obiekt docelowy wywołania zgłosił wyjątek.] System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct&amp; sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +0 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +1255 System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +38 System.Web.UI.WebControls.ObjectDataSourceView.InvokeMethod(ObjectDataSourceMethod method, Boolean disposeInstance, Object&amp; instance) +897 System.Web.UI.WebControls.ObjectDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1848 System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +27 System.Web.UI.WebControls.DataBoundControl.PerformSelect() +261 System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82 System.Web.UI.WebControls.GridView.OnPreRender(EventArgs e) +46 System.Web.UI.Control.PreRenderRecursiveInternal() +108 System.Web.UI.Control.PreRenderRecursiveInternal() +224 System.Web.UI.Control.PreRenderRecursiveInternal() +224 System.Web.UI.Control.PreRenderRecursiveInternal() +224 System.Web.UI.Control.PreRenderRecursiveInternal() +224 System.Web.UI.Control.PreRenderRecursiveInternal() +224 System.Web.UI.Control.PreRenderRecursiveInternal() +224 System.Web.UI.Control.PreRenderRecursiveInternal() +224 System.Web.UI.Control.PreRenderRecursiveInternal() +224 System.Web.UI.Control.PreRenderRecursiveInternal() +224 System.Web.UI.Control.PreRenderRecursiveInternal() +224 System.Web.UI.Control.PreRenderRecursiveInternal() +224 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3394 </code></pre> <p><a href="http://msdn.microsoft.com/en-us/library/ff647598.aspx" rel="nofollow">On this MSDN page</a> I found a nice picture which recommends to catch this kind of exception on the WebPart boundary, but the example they provided is not clear to me (where would this boundary be in my WebPart code?)</p> <p>I would be grateful for any suggestions and examples on how to catch this kind of exception, how to handle it in my code or for any suggestions on how to handle this issue in any other way.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload