Solved

How do i ignore or subsidise an unhandled Exception(Visual studio , C#)

Posted on 2008-11-02
3
819 Views
Last Modified: 2013-12-17
I just dont want my application to spit out any errors.( I have made validation on every fields so theoritically it alerts the user if the field are not set) but after validation the programe still executes and gives me error messages saying the field is not correctly set.


Either i want to know how can we exit the flow of programme which gives me exception

or

How do i ignore or subsidise an unhandled Exception(Visual studio , C#).
Thanks guys
MAIN PROGRAM

============

public void View_Click(object sender, EventArgs e)

        {

            if (IDIR.Checked == true)

            {

                Vpara();

                IDIRD();

            }

private void IDIRD()

        {

            ciscopreface();

            sr.AppendLine("hostname " + ZNumber.Text);

}

 

If ZNumber field is empty the programme throws an exception.

 To avoid that i have used

============================================================

        private void Vpara()

        {

            foreach (Control ctrl in IParameters.Controls)

            {

                if ((ctrl.Visible == true) && (ctrl.Text == String.Empty))

                {

                    MessageBox.Show("Enter ALL the parameters correctly", "Warning");

                }

            }

        }

BUT THE PROBLEM IS THE PRGRAM CONTIUES THE FLOW AND TO  IDIRD(); AND THROWS US AN EXCEPTION.

Either i want to know how can we exit the flow of programme which gives me exception

 

or

 

How do i ignore or subsidise an unhandled Exception(Visual studio , C#).

Thanks guys

Open in new window

0
Comment
Question by:JesuSingarayar
  • 2
3 Comments
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 250 total points
ID: 22861346
Hi JesuSingarayar;

I have modified your code so that IDIRD() is not executed if Vpara() found an error.

Fernando

public void View_Click(object sender, EventArgs e)

{

    if (IDIR.Checked == true)

    {

        // If the function Vpara returns true then it had an error and

        // so execut the return to exit this event handler otherwise execut

        // the function IDIRD.

        if( Vpara() ) return;

        IDIRD();

    }

    

private void IDIRD()

{

    ciscopreface();

    sr.AppendLine("hostname " + ZNumber.Text);

}
 

// Return true from this function if there is an error 

private bool Vpara()

{

    foreach (Control ctrl in IParameters.Controls)

    {

        if ((ctrl.Visible == true) && (ctrl.Text == String.Empty))

        {

            MessageBox.Show("Enter ALL the parameters correctly", "Warning");

            // Error was found so return true.

            return true;

        }

    }

    // No error was found so return false

    return false;

}

Open in new window

0
 

Author Closing Comment

by:JesuSingarayar
ID: 31512455
Thank YOU very much FernandoSoto.
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 22861395
Not a problem, glad I was able to help.  ;=)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now