exception handling RRS feed

  • Question

  • protected void AddRecord(object sender, EventArgs e)



            float CalculatedQty = Int64.Parse(TextBox4.Text);

            float PhysicalQty = Int64.Parse(txt1.Text);
            DateTime StTakdt = Convert.ToDateTime(txtdt1.Text);
            bal pBAL = new bal();
            int intResult = 0;

                intResult = pBAL.Insert5(int.Parse(TextBox5.Text), int.Parse(TextBox2.Text), CalculatedQty, PhysicalQty, StTakdt);

                if (intResult > 0)

                    lbl.Text = "Record Insert Successfully.";
                    lbl.Text = lbl.Text = "AuditID [<b>" + TextBox5.Text + "</b>] alredy exists, try another name";

                throw new Exception("plz enter detail");
            catch (Exception ee)
                Console.WriteLine("{0} Exception caught plz enter detail.", ee);

                lbl.Text = ee.Message.ToString();
                pBAL = null;

            gvdetails.EditIndex = -1;
            // Refresh the list


    when any click on add button without insert any value it will through message plz enter details how it is possible can any body answer me

    • Moved by Carl Cai Wednesday, October 16, 2013 7:30 AM get better support
    Tuesday, October 15, 2013 5:32 AM


  • Hi Raheel,

    Welcome to MSDN forums.

    For this issue, I would suggest you refer to the document of MSDN Library below.


    “A common usage of catch and finally together is to obtain and use resources in a try block, deal with exceptional circumstances in a catch block, and release the resources in the finally block.”

    Now, let’s discuss your code.

    Whether intResult>1 or not, the following code will be executed.

    throw new Exception("plz enter detail");

    Then you will catch the exception in the catch block. So it will throw message “plz enter details”.



    In addition, whether you can catch an exception, the following code marked the Bold will be executed. So there is no value will be inserted in the pBAL control.

                pBAL = null;


    So you can update your code first. If you have any question further, you can post your requirement here.



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, October 16, 2013 7:23 AM