Apache OpenOffice (AOO) Bugzilla – Issue 54060
Basic On Error does not reset for second error handler
Last modified: 2017-05-20 09:24:57 UTC
AFAIK this is a bug, as it differs from VB6 behavior and is not very functional. This is the scenario: error is trapped and sent to error handler, error handler creates new 'on error' handler, second error is not trapped as it should be. The following example should report "TEST" and "TEST2", but only reports TEST followed by an untrapped error. (I presume this is the case, but my version does not seem to report errors - it just stops and highlights the offending line - no pop-up telling me why.) FYI I am running this in an oocalc macro, version 2.0-pre (build 1.9.110 installed with SuSe 9.3 Pro). on error goto test x = 0 y = 1/x exit sub test: on error goto test2 msgbox "TEST: " + str(err) +" " + error y = 1/x exit sub test2: msgbox "TEST2: " +str(err) +" " + error exit sub
Andreas, please have a look at this...
.
Started
STARTED
The way AOO Basic works with error handling (see SbiRuntime::Step()) is that errors cannot nest: when already inside an error handler, only the parent error handlers are searched for to handle an error, not the current one. To leave an error handler, you must first "resume" (possibly with a label), only after that will errors use your new error handler instead of trying to go to the parent. In other words: on error goto test x = 0 y = 1/x exit sub test: on error goto test2 msgbox "TEST: " + str(err) +" " + error resume r ' <--------------------------------------- These 2 lines r: ' <--------------------------------------- fix it y = 1/x exit sub test2: msgbox "TEST2: " +str(err) +" " + error exit sub Now you said this "differs from VB6". Are you sure? From Microsoft for VB.NET (https://msdn.microsoft.com/en-us/library/5hsw66as.aspx) "If the calling procedure has an enabled error handler, it is activated to handle the error. If the calling procedure's error handler is also active, control passes back through previous calling procedures until an enabled, but inactive, error handler is found. If no such error handler is found, the error is fatal at the point at which it actually occurred." Furthermore in Microsoft Office 2007's Excel, even your example has the same error, and mine works. Another error is that you can't refer to err and error after using "on error" in an error handler; that doesn't work even in Excel. Thus resolving NOT_AN_ISSUE.