By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,666 Members | 1,784 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,666 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.