On Local Error Goto
Contents |
On Error If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register on error goto before you can post: click the register link above to proceed. To start
On Error Goto 0 Vbscript
viewing messages, select the forum that you want to visit from the selection below. Results 1 to 5
On Error Goto Line
of 5 Thread: [RESOLVED] On Local Error vs On Error Tweet Thread Tools Show Printable Version Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode
On Error Exit Sub
May 3rd, 2007,06:28 AM #1 VB rookie View Profile View Forum Posts Thread Starter Lively Member Join Date Nov 2006 Posts 105 [RESOLVED] On Local Error vs On Error I saw a snippet of code that contained a statement along the lines of: On Local Error goto ... I have always used On Error goto.... Can someone explain the difference for me? If vba error handling best practices I have On Error in a sub, does that overflow into other areas of the app or is it localized in the sub? How do you do global error trapping? On Global Error? If there is such an error trap, I presume it doesnt over-ride the On Error or On Local Errors within Subs? Where should the global error catching reside (if its possible)? In Form_load of the Form1? Any help on this matter is appreciated. Reply With Quote May 3rd, 2007,06:30 AM #2 Hack View Profile View Forum Posts Super Moderator Join Date Aug 2001 Location Searching for mendhak Posts 58,335 Re: On Local Error vs On Error On Local Error is a hold over from previous versions of VB. It is still available for backward compatibility only. Your practice of using On Error GoTo is correct, and should be the one you continue to follow. Please use [Code]your code goes in here[/Code] tags when posting code. When you have received an answer to your question, please mark it as resolved using the Thread Tools menu. Before posting your question, did you look her
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 or posting ads with us Stack Overflow vba error handling in loop Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow vba error number is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Why would you ever try catch vba use “On Error Goto 0”? up vote 19 down vote favorite 5 Why would you ever use "On Error Goto 0" in a VB6 app? This statement turns the error handler off and would mean that any error would crash the app. Why would http://www.vbforums.com/showthread.php?466768-RESOLVED-On-Local-Error-vs-On-Error this ever be desirable? vb6 error-handling share|improve this question asked Apr 2 '12 at 20:37 CJ7 4,99232114220 4 Well, it's certainly a way of implementing fail-fast –Greg Hewgill Apr 2 '12 at 20:39 I don't have VB6 installed, but presumably any Goto statement to a non-existant label would crash the app. –Sam Axe Apr 2 '12 at 20:40 This sounds like a comment from somebody who either throws in On Error Resume Next at the head of each procedure and then has http://stackoverflow.com/questions/9983464/why-would-you-ever-use-on-error-goto-0 mysterious woes that can't be diagnosed, or one who puts in On Error GoTo MyHandler and there just pops up a MsgBox with the same error anyway. –Bob77 Apr 2 '12 at 21:14 2 Not true at all. It is commonly paired with On Error Resume Next and a test of Err.Number to do inline structured error handling. –Bob77 Apr 3 '12 at 0:52 1 @CraigJ: Remember that the error handling is for that procedure (and children) only. "Turning it off" is NOT global, and allows errors to be handled by the parent. –Deanna Apr 3 '12 at 15:28 | show 9 more comments 4 Answers 4 active oldest votes up vote 35 down vote In VB6, you can specify that you want errors to be handled by particular code later in the routine: Sub Bar() On Error Goto MyHandler ... ...some code that throws an error... ... Exit Sub MyHandler: ...some error handler code (maybe pops up a dialog) End Sub It may be the case, however, that the code that throws the error is localized, and you don't want that same handler for all of the rest of the code in the routine. In that case, you'd use "On Error Goto 0" as follows: Sub Bar() ... On Error Goto MyHandler ...some code that throws an error... On Error Goto 0 ... ... Exit Sub MyHandler: ...some error handler code (maybe pops up a dialog) End Sub Now you have effectively scoped the error handling to execute only if that particular line of code fails.
FORUMSFOR COMPUTER PROFESSIONALS Log In Come Join Us! Are you aComputer / IT professional?Join Tek-Tips Forums! Talk With Other Members Be Notified Of ResponsesTo http://www.tek-tips.com/viewthread.cfm?qid=1062531 Your Posts Keyword Search One-Click Access To YourFavorite Forums Automated SignaturesOn Your Posts Best Of All, It's Free! Join Us! *Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail. Posting Guidelines Promoting, selling, recruiting, coursework and thesis posting is forbidden.Tek-Tips Posting Policies Jobs Jobs from Indeed What: Where: jobs by Link To error goto This Forum! Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.Just copy and paste the BBCode HTML Markdown MediaWiki reStructuredText code below into your site. Visual Basic(Microsoft): Version 5 & 6 Forum at Tek-Tips HomeForumsProgrammersLanguagesVisual Basic(Microsoft): Version 5 & 6 Forum On Local Error vs On Error thread222-1062531 Forum Search FAQs Links MVPs On Local on error goto Error vs On Error On Local Error vs On Error Hackster (Programmer) (OP) 18 May 05 08:56 What is the difference between using On Local Error Goto and On Error Goto? RE: On Local Error vs On Error jebenson (TechnicalUser) 18 May 05 10:11 There is no functional difference between On Error and On Local Error.The latter is a deprecated holdover from earlier versions of VB to ease upgrading code written in those earlier versions.In VB6, the Local keyword is ignored. I used to rock and roll every night and party every day.Then it was every other day.Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson Red Flag This Post Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework. Cancel Red Flag SubmittedThank you for helping keep Tek-Tips Forums free from inappropriate posts.The Tek-Tips staff will check this out and take appropriate action. Close Reply To This Thread Posting in the T