470,590 Members | 2,525 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,590 developers. It's quick & easy.

How can I close my application when I got an error?

I have a window Application. this.close(); doesn't stop and close my
application when I get an error. Instead it continues trying to execute the
following codes. What code do I need to the application to exit where it
catches the exception and close down the application?

Thanks, Alpha

conDB = new SqlConnection(conStr);

try
{
conDB.Open();
scUpdate = conDB.CreateCommand();
conDB.Close();
}
catch(Exception ex)
{
MessageBox.Show("Error connecting to the database server. VMS can't run
with out database connection and VMS will be closing down. " + ex.ToString()+
"Please contact your support person.", "VMS - Database Open Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
this.Close();

}

Nov 17 '05 #1
4 3512
Use Application.Exit.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Alpha" <Al***@discussions.microsoft.com> wrote in message
news:C0**********************************@microsof t.com...
I have a window Application. this.close(); doesn't stop and close my
application when I get an error. Instead it continues trying to execute
the
following codes. What code do I need to the application to exit where it
catches the exception and close down the application?

Thanks, Alpha

conDB = new SqlConnection(conStr);

try
{
conDB.Open();
scUpdate = conDB.CreateCommand();
conDB.Close();
}
catch(Exception ex)
{
MessageBox.Show("Error connecting to the database server. VMS can't run
with out database connection and VMS will be closing down. " +
ex.ToString()+
"Please contact your support person.", "VMS - Database Open Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
this.Close();

}

Nov 17 '05 #2
Use System.Environment.Exit
Peter

"Alpha" <Al***@discussions.microsoft.com> wrote in message
news:C0**********************************@microsof t.com...
I have a window Application. this.close(); doesn't stop and close my
application when I get an error. Instead it continues trying to execute
the
following codes. What code do I need to the application to exit where it
catches the exception and close down the application?

Thanks, Alpha

conDB = new SqlConnection(conStr);

try
{
conDB.Open();
scUpdate = conDB.CreateCommand();
conDB.Close();
}
catch(Exception ex)
{
MessageBox.Show("Error connecting to the database server. VMS can't run
with out database connection and VMS will be closing down. " +
ex.ToString()+
"Please contact your support person.", "VMS - Database Open Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
this.Close();

}

Nov 17 '05 #3
It's asking for ExitCode, as System.Environment.Exit(ExitCode), when I
compile the program. What should I put in there? 0?
Thanks.

"Peter Bromberg [MVP]" wrote:
Use System.Environment.Exit
Peter

"Alpha" <Al***@discussions.microsoft.com> wrote in message
news:C0**********************************@microsof t.com...
I have a window Application. this.close(); doesn't stop and close my
application when I get an error. Instead it continues trying to execute
the
following codes. What code do I need to the application to exit where it
catches the exception and close down the application?

Thanks, Alpha

conDB = new SqlConnection(conStr);

try
{
conDB.Open();
scUpdate = conDB.CreateCommand();
conDB.Close();
}
catch(Exception ex)
{
MessageBox.Show("Error connecting to the database server. VMS can't run
with out database connection and VMS will be closing down. " +
ex.ToString()+
"Please contact your support person.", "VMS - Database Open Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
this.Close();

}


Nov 17 '05 #4
I tried the Application.Exit in place of this.Close() but I got the same
result. The application just continues with the codes and give more error
message.

Thanks, Alpha

"Bob Powell [MVP]" wrote:
Use Application.Exit.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Alpha" <Al***@discussions.microsoft.com> wrote in message
news:C0**********************************@microsof t.com...
I have a window Application. this.close(); doesn't stop and close my
application when I get an error. Instead it continues trying to execute
the
following codes. What code do I need to the application to exit where it
catches the exception and close down the application?

Thanks, Alpha

conDB = new SqlConnection(conStr);

try
{
conDB.Open();
scUpdate = conDB.CreateCommand();
conDB.Close();
}
catch(Exception ex)
{
MessageBox.Show("Error connecting to the database server. VMS can't run
with out database connection and VMS will be closing down. " +
ex.ToString()+
"Please contact your support person.", "VMS - Database Open Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
this.Close();

}


Nov 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by PawelR | last post: by
1 post views Thread by Alpha | last post: by
reply views Thread by Yelena Varshal via AccessMonster.com | last post: by
8 posts views Thread by Rodrigo Juarez | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.