Solved

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

Posted on 2008-11-02
3
827 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 63

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 63

Expert Comment

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

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

691 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