How to handle a exception error in c#?

2 posts, 0 answers
  1. Yoongu
    Yoongu avatar
    16 posts
    Member since:
    Sep 2014

    Posted 25 Mar 2015 Link to this post


    I use the "try...catch" in order to save the data to the server.
    And I was exception handling in the "throw ex".

    However, this doesn't display page when an error occurs.
    So I have to debug to check the exception message.

    In such a case, do I need to process How?

    here my code.

        <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
        <script type="text/javascript">
            function Update() {
                var batchManager = grid2.get_batchEditingManager();
        <form id="form" runat="server">
           <telerik:RadAjaxPanel ID="RadAjaxPanel2" runat="server" Height="100%" Width="100%" HorizontalAlign="NotSet" OnAjaxRequest="RadAjaxPanel2_AjaxRequest">
                <telerik:RadGrid ID="RadGrid2" runat="server" AutoGenerateColumns="False" Culture="ko-KR" GroupPanelPosition="Top" OnNeedDataSource="RadGrid2_NeedDataSource" OnBatchEditCommand="RadGrid2_BatchEditCommand" OnItemCreated="RadGrid2_ItemCreated" Height="445px" OnPreRender="RadGrid2_PreRender" AllowAutomaticUpdates="True" ShowFooter="True">
                    <ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True" AllowKeyboardNavigation="True">
                        <ClientEvents OnRowCreated="RowCreated" OnBatchEditCellValueChanged="RadGrid2_OnBatchEditCellValueChanged" />
                        <KeyboardNavigationSettings AllowSubmitOnEnter="True" CancelChangesKey="D1" />
                        <Scrolling AllowScroll="True" UseStaticHeaders="True" />
                    <MasterTableView EditMode="Batch" BatchEditingSettings-EditType="Cell">

            protected override void OnPreInit(EventArgs e)
                baseScriptManager = new ScriptManager();
                baseScriptManager.AsyncPostBackTimeout = 600;
                Page.Items[typeof(ScriptManager)] = baseScriptManager;
            protected override void OnPreLoad(EventArgs e)
                Page.Items[typeof(ScriptManager)] = null;
                baseScriptManager.AllowCustomErrorsRedirect = true;
                baseScriptManager.AsyncPostBackError += this.baseScriptManager_AsyncPostBackError;
            private void baseScriptManager_AsyncPostBackError(object sender, AsyncPostBackErrorEventArgs e)
                baseScriptManager.AsyncPostBackErrorMessage = e.Exception.Message;
            protected void RadGrid2_BatchEditCommand(object sender, GridBatchEditingEventArgs e)
                using (DbConnection connection = db.CreateConnection())
                    DbTransaction transaction = connection.BeginTransaction();
                        DbCommand dbCommand = null;
                        foreach (DBParameter DBParameter in parameters)
                            dbCommand = db.GetStoredProcCommand("uspw_test1");
                            dbCommand.CommandTimeout = commandTimeout;
                            if (DBParameter != null)
                                foreach (Parameter parameter in DBParameter.ListParameter)
                                    db.AddInParameter(dbCommand, parameter.Name, parameter.DBType, parameter.Value);
                            result += db.ExecuteNonQuery(dbCommand, transaction);
                        // Commit the transaction
                    catch (System.Exception ex)
                        // Rollback transaction
                        throw ex;
  2. Angel Petrov
    Angel Petrov avatar
    1044 posts

    Posted 30 Mar 2015 Link to this post


    I am experiencing difficulties understanding the query. Do you want to display the exception message to the user?

    In general it is a string and you should be able to display it in some control after the insert/update fails. An example of such an approach can be observed in this online demo where the exception is displayed in a RadListBox.

    Angel Petrov

    See What's Next in App Development. Register for TelerikNEXT.

Back to Top