Home All Groups Group Topic Archive Search About

How to Exit an application properly on Error

Author
14 Jan 2006 4:00 PM
Rob
I have the following code...

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

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

Thanks!

Author
14 Jan 2006 4:04 PM
Cyril Gupta
Hello,

You could try End.

You can also set all forms and classes to Nothing

myForm = Nothing

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

Regards
Cyril Gupta
Author
14 Jan 2006 4:16 PM
Rob
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 !

Show quoteHide quote
"Cyril Gupta" <nom***@mail.com> wrote in message
news:OqCDYRSGGHA.2704@TK2MSFTNGP15.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.Exit waits for the message queue to
> finish proccessing... Maybe that is why it did not exit immediately.
>
> Regards
> Cyril Gupta
>
Author
14 Jan 2006 4:27 PM
Herfried K. Wagner [MVP]
"Rob" <rwch***@comcast.net> schrieb:
> 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 ?

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/>
Author
14 Jan 2006 4:45 PM
m.posseth
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/default.asp?url=/library/en-us/vblr7/html/vastmend.asp

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



regards

Michel Posseth [MCP]



Show quoteHide quote
"Rob" <rwch***@comcast.net> wrote in message
news:lpednexIAaMjvlTeRVn-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" <nom***@mail.com> wrote in message
> news:OqCDYRSGGHA.2704@TK2MSFTNGP15.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.Exit waits for the message queue
>> to finish proccessing... Maybe that is why it did not exit immediately.
>>
>> Regards
>> Cyril Gupta
>>
>
>
Author
14 Jan 2006 5:25 PM
Rob
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 ?



Show quoteHide quote
"m.posseth" <mich***@nohausystems.nl> wrote in message
news:%2399oynSGGHA.648@TK2MSFTNGP14.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/default.asp?url=/library/en-us/vblr7/html/vastmend.asp
>
> The right way to end an application is to  clean / interupt  the calling
> chain
>
>
>
> regards
>
> Michel Posseth [MCP]
>
>
>
> "Rob" <rwch***@comcast.net> wrote in message
> news:lpednexIAaMjvlTeRVn-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" <nom***@mail.com> wrote in message
>> news:OqCDYRSGGHA.2704@TK2MSFTNGP15.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.Exit waits for the message queue
>>> to finish proccessing... Maybe that is why it did not exit immediately.
>>>
>>> Regards
>>> Cyril Gupta
>>>
>>
>>
>
>
Author
14 Jan 2006 5:35 PM
m.posseth
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]


Show quoteHide quote
"Rob" <rwch***@comcast.net> wrote in message
news:HdudncbvyriIqVTeRVn-vg@comcast.com...
> 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" <mich***@nohausystems.nl> wrote in message
> news:%2399oynSGGHA.648@TK2MSFTNGP14.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/default.asp?url=/library/en-us/vblr7/html/vastmend.asp
>>
>> The right way to end an application is to  clean / interupt  the calling
>> chain
>>
>>
>>
>> regards
>>
>> Michel Posseth [MCP]
>>
>>
>>
>> "Rob" <rwch***@comcast.net> wrote in message
>> news:lpednexIAaMjvlTeRVn-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" <nom***@mail.com> wrote in message
>>> news:OqCDYRSGGHA.2704@TK2MSFTNGP15.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.Exit waits for the message queue
>>>> to finish proccessing... Maybe that is why it did not exit immediately.
>>>>
>>>> Regards
>>>> Cyril Gupta
>>>>
>>>
>>>
>>
>>
>
>
Author
14 Jan 2006 5:46 PM
Rob
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



Show quoteHide quote
"m.posseth" <mich***@nohausystems.nl> wrote in message
news:%23slblDTGGHA.3856@TK2MSFTNGP12.phx.gbl...
>
> 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" <rwch***@comcast.net> wrote in message
> news:HdudncbvyriIqVTeRVn-vg@comcast.com...
>> 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" <mich***@nohausystems.nl> wrote in message
>> news:%2399oynSGGHA.648@TK2MSFTNGP14.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/default.asp?url=/library/en-us/vblr7/html/vastmend.asp
>>>
>>> The right way to end an application is to  clean / interupt  the calling
>>> chain
>>>
>>>
>>>
>>> regards
>>>
>>> Michel Posseth [MCP]
>>>
>>>
>>>
>>> "Rob" <rwch***@comcast.net> wrote in message
>>> news:lpednexIAaMjvlTeRVn-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" <nom***@mail.com> wrote in message
>>>> news:OqCDYRSGGHA.2704@TK2MSFTNGP15.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.Exit waits for the message
>>>>> queue to finish proccessing... Maybe that is why it did not exit
>>>>> immediately.
>>>>>
>>>>> Regards
>>>>> Cyril Gupta
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
Author
14 Jan 2006 8:54 PM
m.posseth
Well in my opinion your program should in the described situation raise an
exception ,  and so shutdown

regards

Michel Posseth [MCP]



Show quoteHide quote
"Rob" <rwch***@comcast.net> wrote in message
news:7vmdnQLvU9hJpVTeRVn-hw@comcast.com...
> 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" <mich***@nohausystems.nl> wrote in message
> news:%23slblDTGGHA.3856@TK2MSFTNGP12.phx.gbl...
>>
>> 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" <rwch***@comcast.net> wrote in message
>> news:HdudncbvyriIqVTeRVn-vg@comcast.com...
>>> 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" <mich***@nohausystems.nl> wrote in message
>>> news:%2399oynSGGHA.648@TK2MSFTNGP14.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/default.asp?url=/library/en-us/vblr7/html/vastmend.asp
>>>>
>>>> The right way to end an application is to  clean / interupt  the
>>>> calling chain
>>>>
>>>>
>>>>
>>>> regards
>>>>
>>>> Michel Posseth [MCP]
>>>>
>>>>
>>>>
>>>> "Rob" <rwch***@comcast.net> wrote in message
>>>> news:lpednexIAaMjvlTeRVn-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" <nom***@mail.com> wrote in message
>>>>> news:OqCDYRSGGHA.2704@TK2MSFTNGP15.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.Exit waits for the message
>>>>>> queue to finish proccessing... Maybe that is why it did not exit
>>>>>> immediately.
>>>>>>
>>>>>> Regards
>>>>>> Cyril Gupta
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>