How to Exit an application properly on Error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rob

    How to Exit an application properly on Error

    I have the following code...

    Try
    da.Fill(ds,"mys et")
    Catch exc as exception
    Msgbox("Check Connection string Info")
    Ffrm.Dispose()
    Application.Exi t()
    Exit Sub
    EndTry

    I noticed that the Application.Exi t() alone did not exit the Sub
    Procedure... so I added the Exit Sub. Why doesn't Application.Exi t()
    alone work ?

    Thanks!


  • Cyril Gupta

    #2
    Re: How to Exit an application properly on Error

    Hello,

    You could try End.

    You can also set all forms and classes to Nothing

    myForm = Nothing

    And then call End. I think Application.Exi t waits for the message queue to
    finish proccessing... Maybe that is why it did not exit immediately.

    Regards
    Cyril Gupta


    Comment

    • Rob

      #3
      Re: How to Exit an application properly on Error

      End works...

      Regarding... "You can also set all forms and classes to Nothing"

      Is there some generic code that one can run that will loop thru all "open"
      objects and sets them to nothing ?

      Thanks !

      "Cyril Gupta" <nomail@mail.co m> wrote in message
      news:OqCDYRSGGH A.2704@TK2MSFTN GP15.phx.gbl...[color=blue]
      > Hello,
      >
      > You could try End.
      >
      > You can also set all forms and classes to Nothing
      >
      > myForm = Nothing
      >
      > And then call End. I think Application.Exi t waits for the message queue to
      > finish proccessing... Maybe that is why it did not exit immediately.
      >
      > Regards
      > Cyril Gupta
      >[/color]


      Comment

      • Herfried K. Wagner [MVP]

        #4
        Re: How to Exit an application properly on Error

        "Rob" <rwchome@comcas t.net> schrieb:[color=blue]
        > Regarding... "You can also set all forms and classes to Nothing"
        >
        > Is there some generic code that one can run that will loop thru all "open"
        > objects and sets them to nothing ?[/color]

        Setting the variables pointing to forms to 'Nothing' doesn't make much
        sense. Instead, you may want to call the main form's 'Close' method and/or
        the forms' 'Close' methods.

        --
        M S Herfried K. Wagner
        M V P <URL:http://dotnet.mvps.org/>
        V B <URL:http://classicvb.org/petition/>

        Comment

        • m.posseth

          #5
          Re: How to Exit an application properly on Error

          Using end to just end the lifecycle of an application is considered bad
          coding practice

          you should use End sparingly and only when you need and can terminate
          immediatly ( normally you can`t , that is why it is bad coding practice :-)



          The right way to end an application is to clean / interupt the calling
          chain



          regards

          Michel Posseth [MCP]



          "Rob" <rwchome@comcas t.net> wrote in message
          news:lpednexIAa MjvlTeRVn-jw@comcast.com. ..[color=blue]
          > End works...
          >
          > Regarding... "You can also set all forms and classes to Nothing"
          >
          > Is there some generic code that one can run that will loop thru all "open"
          > objects and sets them to nothing ?
          >
          > Thanks !
          >
          > "Cyril Gupta" <nomail@mail.co m> wrote in message
          > news:OqCDYRSGGH A.2704@TK2MSFTN GP15.phx.gbl...[color=green]
          >> Hello,
          >>
          >> You could try End.
          >>
          >> You can also set all forms and classes to Nothing
          >>
          >> myForm = Nothing
          >>
          >> And then call End. I think Application.Exi t waits for the message queue
          >> to finish proccessing... Maybe that is why it did not exit immediately.
          >>
          >> Regards
          >> Cyril Gupta
          >>[/color]
          >
          >[/color]


          Comment

          • Rob

            #6
            Re: How to Exit an application properly on Error

            Thanks Michel,

            So my question kind of still remains... before using an "End" or even "Exit
            Sub"....

            Is there some generic code that will loop thru all "open"
            objects and clean them up ?



            "m.posseth" <michelp@nohaus ystems.nl> wrote in message
            news:%2399oynSG GHA.648@TK2MSFT NGP14.phx.gbl.. .[color=blue]
            > Using end to just end the lifecycle of an application is considered bad
            > coding practice
            >
            > you should use End sparingly and only when you need and can terminate
            > immediatly ( normally you can`t , that is why it is bad coding practice
            > :-)
            >
            > http://msdn.microsoft.com/library/de...l/vastmend.asp
            >
            > The right way to end an application is to clean / interupt the calling
            > chain
            >
            >
            >
            > regards
            >
            > Michel Posseth [MCP]
            >
            >
            >
            > "Rob" <rwchome@comcas t.net> wrote in message
            > news:lpednexIAa MjvlTeRVn-jw@comcast.com. ..[color=green]
            >> End works...
            >>
            >> Regarding... "You can also set all forms and classes to Nothing"
            >>
            >> Is there some generic code that one can run that will loop thru all
            >> "open" objects and sets them to nothing ?
            >>
            >> Thanks !
            >>
            >> "Cyril Gupta" <nomail@mail.co m> wrote in message
            >> news:OqCDYRSGGH A.2704@TK2MSFTN GP15.phx.gbl...[color=darkred]
            >>> Hello,
            >>>
            >>> You could try End.
            >>>
            >>> You can also set all forms and classes to Nothing
            >>>
            >>> myForm = Nothing
            >>>
            >>> And then call End. I think Application.Exi t waits for the message queue
            >>> to finish proccessing... Maybe that is why it did not exit immediately.
            >>>
            >>> Regards
            >>> Cyril Gupta
            >>>[/color]
            >>
            >>[/color]
            >
            >[/color]


            Comment

            • m.posseth

              #7
              Re: How to Exit an application properly on Error


              Rob ,,

              Not that i know of ,,,, however it shouldn`t be necesary to do so cleaning
              up the base object should result in the disposing of evenntuall satelites

              if you need to use End to stop an app this means that something is wrong in
              your apps design


              regards

              Michel Posseth [MCP]


              "Rob" <rwchome@comcas t.net> wrote in message
              news:Hdudncbvyr iIqVTeRVn-vg@comcast.com. ..[color=blue]
              > Thanks Michel,
              >
              > So my question kind of still remains... before using an "End" or even
              > "Exit Sub"....
              >
              > Is there some generic code that will loop thru all "open"
              > objects and clean them up ?
              >
              >
              >
              > "m.posseth" <michelp@nohaus ystems.nl> wrote in message
              > news:%2399oynSG GHA.648@TK2MSFT NGP14.phx.gbl.. .[color=green]
              >> Using end to just end the lifecycle of an application is considered bad
              >> coding practice
              >>
              >> you should use End sparingly and only when you need and can terminate
              >> immediatly ( normally you can`t , that is why it is bad coding practice
              >> :-)
              >>
              >> http://msdn.microsoft.com/library/de...l/vastmend.asp
              >>
              >> The right way to end an application is to clean / interupt the calling
              >> chain
              >>
              >>
              >>
              >> regards
              >>
              >> Michel Posseth [MCP]
              >>
              >>
              >>
              >> "Rob" <rwchome@comcas t.net> wrote in message
              >> news:lpednexIAa MjvlTeRVn-jw@comcast.com. ..[color=darkred]
              >>> End works...
              >>>
              >>> Regarding... "You can also set all forms and classes to Nothing"
              >>>
              >>> Is there some generic code that one can run that will loop thru all
              >>> "open" objects and sets them to nothing ?
              >>>
              >>> Thanks !
              >>>
              >>> "Cyril Gupta" <nomail@mail.co m> wrote in message
              >>> news:OqCDYRSGGH A.2704@TK2MSFTN GP15.phx.gbl...
              >>>> Hello,
              >>>>
              >>>> You could try End.
              >>>>
              >>>> You can also set all forms and classes to Nothing
              >>>>
              >>>> myForm = Nothing
              >>>>
              >>>> And then call End. I think Application.Exi t waits for the message queue
              >>>> to finish proccessing... Maybe that is why it did not exit immediately.
              >>>>
              >>>> Regards
              >>>> Cyril Gupta
              >>>>
              >>>
              >>>[/color]
              >>
              >>[/color]
              >
              >[/color]


              Comment

              • Rob

                #8
                Re: How to Exit an application properly on Error

                Let's say you have code that is going to fill a data set via a Command
                object / stored proc...
                If the connection string is bad (held in the config file) OR a stored proc
                is missing (the one you are calling)... then for all intents and purposes my
                program may as well shut down...

                Do I only need to dispose of the Form ? what about any connections ? other
                varibales ? What is left over as a "problem" if the application just "Ends"
                at this point ?

                Thanks,
                Rob



                "m.posseth" <michelp@nohaus ystems.nl> wrote in message
                news:%23slblDTG GHA.3856@TK2MSF TNGP12.phx.gbl. ..[color=blue]
                >
                > Rob ,,
                >
                > Not that i know of ,,,, however it shouldn`t be necesary to do so cleaning
                > up the base object should result in the disposing of evenntuall
                > satelites
                >
                > if you need to use End to stop an app this means that something is wrong
                > in your apps design
                >
                >
                > regards
                >
                > Michel Posseth [MCP]
                >
                >
                > "Rob" <rwchome@comcas t.net> wrote in message
                > news:Hdudncbvyr iIqVTeRVn-vg@comcast.com. ..[color=green]
                >> Thanks Michel,
                >>
                >> So my question kind of still remains... before using an "End" or even
                >> "Exit Sub"....
                >>
                >> Is there some generic code that will loop thru all "open"
                >> objects and clean them up ?
                >>
                >>
                >>
                >> "m.posseth" <michelp@nohaus ystems.nl> wrote in message
                >> news:%2399oynSG GHA.648@TK2MSFT NGP14.phx.gbl.. .[color=darkred]
                >>> Using end to just end the lifecycle of an application is considered bad
                >>> coding practice
                >>>
                >>> you should use End sparingly and only when you need and can terminate
                >>> immediatly ( normally you can`t , that is why it is bad coding practice
                >>> :-)
                >>>
                >>> http://msdn.microsoft.com/library/de...l/vastmend.asp
                >>>
                >>> The right way to end an application is to clean / interupt the calling
                >>> chain
                >>>
                >>>
                >>>
                >>> regards
                >>>
                >>> Michel Posseth [MCP]
                >>>
                >>>
                >>>
                >>> "Rob" <rwchome@comcas t.net> wrote in message
                >>> news:lpednexIAa MjvlTeRVn-jw@comcast.com. ..
                >>>> End works...
                >>>>
                >>>> Regarding... "You can also set all forms and classes to Nothing"
                >>>>
                >>>> Is there some generic code that one can run that will loop thru all
                >>>> "open" objects and sets them to nothing ?
                >>>>
                >>>> Thanks !
                >>>>
                >>>> "Cyril Gupta" <nomail@mail.co m> wrote in message
                >>>> news:OqCDYRSGGH A.2704@TK2MSFTN GP15.phx.gbl...
                >>>>> Hello,
                >>>>>
                >>>>> You could try End.
                >>>>>
                >>>>> You can also set all forms and classes to Nothing
                >>>>>
                >>>>> myForm = Nothing
                >>>>>
                >>>>> And then call End. I think Application.Exi t waits for the message
                >>>>> queue to finish proccessing... Maybe that is why it did not exit
                >>>>> immediately.
                >>>>>
                >>>>> Regards
                >>>>> Cyril Gupta
                >>>>>
                >>>>
                >>>>
                >>>
                >>>[/color]
                >>
                >>[/color]
                >
                >[/color]


                Comment

                • m.posseth

                  #9
                  Re: How to Exit an application properly on Error

                  Well in my opinion your program should in the described situation raise an
                  exception , and so shutdown

                  regards

                  Michel Posseth [MCP]



                  "Rob" <rwchome@comcas t.net> wrote in message
                  news:7vmdnQLvU9 hJpVTeRVn-hw@comcast.com. ..[color=blue]
                  > Let's say you have code that is going to fill a data set via a Command
                  > object / stored proc...
                  > If the connection string is bad (held in the config file) OR a stored
                  > proc is missing (the one you are calling)... then for all intents and
                  > purposes my program may as well shut down...
                  >
                  > Do I only need to dispose of the Form ? what about any connections ?
                  > other varibales ? What is left over as a "problem" if the application
                  > just "Ends" at this point ?
                  >
                  > Thanks,
                  > Rob
                  >
                  >
                  >
                  > "m.posseth" <michelp@nohaus ystems.nl> wrote in message
                  > news:%23slblDTG GHA.3856@TK2MSF TNGP12.phx.gbl. ..[color=green]
                  >>
                  >> Rob ,,
                  >>
                  >> Not that i know of ,,,, however it shouldn`t be necesary to do so
                  >> cleaning up the base object should result in the disposing of evenntuall
                  >> satelites
                  >>
                  >> if you need to use End to stop an app this means that something is wrong
                  >> in your apps design
                  >>
                  >>
                  >> regards
                  >>
                  >> Michel Posseth [MCP]
                  >>
                  >>
                  >> "Rob" <rwchome@comcas t.net> wrote in message
                  >> news:Hdudncbvyr iIqVTeRVn-vg@comcast.com. ..[color=darkred]
                  >>> Thanks Michel,
                  >>>
                  >>> So my question kind of still remains... before using an "End" or even
                  >>> "Exit Sub"....
                  >>>
                  >>> Is there some generic code that will loop thru all "open"
                  >>> objects and clean them up ?
                  >>>
                  >>>
                  >>>
                  >>> "m.posseth" <michelp@nohaus ystems.nl> wrote in message
                  >>> news:%2399oynSG GHA.648@TK2MSFT NGP14.phx.gbl.. .
                  >>>> Using end to just end the lifecycle of an application is considered
                  >>>> bad coding practice
                  >>>>
                  >>>> you should use End sparingly and only when you need and can terminate
                  >>>> immediatly ( normally you can`t , that is why it is bad coding
                  >>>> practice :-)
                  >>>>
                  >>>> http://msdn.microsoft.com/library/de...l/vastmend.asp
                  >>>>
                  >>>> The right way to end an application is to clean / interupt the
                  >>>> calling chain
                  >>>>
                  >>>>
                  >>>>
                  >>>> regards
                  >>>>
                  >>>> Michel Posseth [MCP]
                  >>>>
                  >>>>
                  >>>>
                  >>>> "Rob" <rwchome@comcas t.net> wrote in message
                  >>>> news:lpednexIAa MjvlTeRVn-jw@comcast.com. ..
                  >>>>> End works...
                  >>>>>
                  >>>>> Regarding... "You can also set all forms and classes to Nothing"
                  >>>>>
                  >>>>> Is there some generic code that one can run that will loop thru all
                  >>>>> "open" objects and sets them to nothing ?
                  >>>>>
                  >>>>> Thanks !
                  >>>>>
                  >>>>> "Cyril Gupta" <nomail@mail.co m> wrote in message
                  >>>>> news:OqCDYRSGGH A.2704@TK2MSFTN GP15.phx.gbl...
                  >>>>>> Hello,
                  >>>>>>
                  >>>>>> You could try End.
                  >>>>>>
                  >>>>>> You can also set all forms and classes to Nothing
                  >>>>>>
                  >>>>>> myForm = Nothing
                  >>>>>>
                  >>>>>> And then call End. I think Application.Exi t waits for the message
                  >>>>>> queue to finish proccessing... Maybe that is why it did not exit
                  >>>>>> immediately.
                  >>>>>>
                  >>>>>> Regards
                  >>>>>> Cyril Gupta
                  >>>>>>
                  >>>>>
                  >>>>>
                  >>>>
                  >>>>
                  >>>
                  >>>[/color]
                  >>
                  >>[/color]
                  >
                  >[/color]


                  Comment

                  Working...