Error Goto End Sub
Contents |
resources Windows Server 2012 resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft Imagine Microsoft Student Partners ISV Startups TechRewards Events Community vba on error goto exit sub Magazine Forums Blogs Channel 9 Documentation APIs and reference Dev
On Error Exit Sub Excel Vba
centers Retired content Samples We’re sorry. The content you requested has been removed. You’ll be auto
On Error Exit Sub Vbscript
redirected in 1 second. Visual Basic Language Reference Statements F-P Statements F-P Statements On Error Statement On Error Statement On Error Statement For Each...Next Statement For...Next Statement
On Error Goto
Function Statement Get Statement GoTo Statement If...Then...Else Statement Implements Statement Imports Statement (.NET Namespace and Type) Imports Statement (XML Namespace) Inherits Statement Interface Statement Mid Statement Module Statement Namespace Statement On Error Statement Operator Statement Option
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers vba ignore error or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x on error goto 0 Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it vba on error goto 0 only takes a minute: Sign up Error Handler - Exit Sub vs. End Sub up vote 13 down vote favorite 1 Why would I want to get out of an Error Handler (after handling) with an Exit Sub instead of https://msdn.microsoft.com/en-us/library/5hsw66as.aspx just letting it go to the End Sub? I'm sure it's simple. I just don't understand. Thanks for any help. Example: Public Sub SubA() On Error Goto ProcError ''# other code MsgBox FuncA() ProcExit: Exit Sub ProcError: MsgBox Err.Description Resume ProcExit End Sub vba vb6 error-handling share|improve this question edited Sep 4 '09 at 12:06 AnthonyWJones 144k22195273 asked Sep 4 '09 at 3:53 RNamo add a comment| 2 Answers 2 active oldest votes up vote 19 down vote accepted Your http://stackoverflow.com/questions/1377152/error-handler-exit-sub-vs-end-sub ProcExit label is your place where you release all the resources whether an error happened or not. For instance: Public Sub SubA() On Error Goto ProcError Connection.Open Open File for Writing SomePreciousResource.GrabIt ProcExit: Connection.Close Connection = Nothing Close File SomePreciousResource.Release Exit Sub ProcError: MsgBox Err.Description Resume ProcExit End Sub share|improve this answer answered Sep 4 '09 at 5:08 AngryHacker 23.1k60198387 1 +1. And, obviously, if you don't need to close or release any resources, there's no need for it and you can just fall through to the End Sub. –MarkJ Sep 4 '09 at 8:16 @MarkJ: Thats probably Ok but I'd be uncomfortable with that, If the error has truely been "handled" I'd prefer to Resume to ProcExit even if its immediately followed with Exit Sub. –AnthonyWJones Sep 4 '09 at 12:05 7 Wouldn't this cause an infinite loop if something below ProcExit raises an error? –Mike Spross Sep 5 '09 at 7:19 add a comment| up vote 1 down vote Typically if you have database connections or other objects declared that, whether used safely or created prior to your exception, will need to be cleaned up (disposed of), then returning your error handling code back to the ProcExit entry point will allow you to do your garbage collection in both cases. If you drop out of your procedure by falling to Exit Sub, you may risk having a yucky build-up of instantiated o
General > how to do On Error Exit Sub Thread Tools Display Modes #1 09-13-2005, 07:31 PM eyes Regular Join Date: Feb 2005 Posts: 52 how http://www.xtremevbtalk.com/general/237826-error-exit-sub.html to do On Error Exit Sub I have a couple of Subs that i wish to implement an error handling procedure such that, if there is any runtime errors, it calls for Exit Sub. I tried to use the following but doesn't work. Sub Main() On Error Goto ErrHandle ... Exit Sub ErrHandle: Exit Sub End Sub Can anyone help please, thanks. eyes View Public Profile Find all posts by eyes on error #2 09-13-2005, 08:41 PM Cerian Knight Multi-Technologist Super Moderator* Expert * Join Date: May 2004 Location: Michigan Posts: 4,102 There does not seem to be anything that would prevent an error from exiting in your example. Cerian Knight View Public Profile Find all posts by Cerian Knight #3 09-13-2005, 08:47 PM Lintz Senior Contributor Join Date: Mar 2003 Location: on error goto The 19th Hole Posts: 989 You don't need the 2nd Exit Sub either. Lintz View Public Profile Visit Lintz's homepage! Find all posts by Lintz #4 09-14-2005, 03:09 AM eyes Regular Join Date: Feb 2005 Posts: 52 Removed 2nd Exit Sub but Still not working. In my main sub, i called some other procedures. could it be failing because of that? What other ways can i go around it? any advice? eyes View Public Profile Find all posts by eyes #5 09-14-2005, 03:18 AM webbone Hydrogen Powered Administrator* Expert * Join Date: Jul 2003 Location: Sacramento, CA Posts: 6,090 Can you explain what you are trying to achieve? Just exiting a sub when an error occurs will probably set you up for MORE errors. If you are trying to debug a problem, then you should have an error handler in EACH sub - you can do something like this: Code: Private Sub Sasquatch () On Error Goto LocalError_Handler 'your sasquatch code goes here... Exit Sub LocalError_Handler: MsgBox "Error occurred in Sasquatch - " & Err.Number & " " & Err.Description 'if you care to do something to actually HANDLE the error, that code goes here 'followed by Resume ??? (depends on your error handl