[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 273
  • Last Modified:

Terminating an application

Hi

I have some code in a form which attempts to connect to a database i.e.

        Try
            objConnection.Open()
        Catch ex As Exception
            MessageBox.Show("Exception opening database: " + ex.Message)
            ' Close the application
            Application.Exit()
        End Try

         Dim mystring As String = "Hello World"

If the database can't be connected to then the exception is captured as expected. However, the line Application.Exit that I have added does not immediately close the application because, for example, the line with mystring is still called.

My question is, how can I catch the exception and end the application without other code being called?

Issac
0
IssacJones
Asked:
IssacJones
4 Solutions
 
nmarunCommented:
Try the Close() method instead of the Application.Exit() call.

Arun
0
 
rushtoshankarCommented:
Hi,
Are you calling Application.Exit() from main form? try close instead.
0
 
nepaluzCommented:
as per above try the Me.Close() method or add Exit Sub after the Application.Exit() call
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
IssacJonesAuthor Commented:
I don't have a main form. I am creating and calling the forms from Sub Main in a module I have created.
0
 
nepaluzCommented:
add Exit Sub after the Application.Exit() call
0
 
VipulKadiaCommented:
Just write End instead of Application.Exit()
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now