Issue 54060 - Basic On Error does not reset for second error handler
Summary: Basic On Error does not reset for second error handler
Status: CLOSED NOT_AN_OOO_ISSUE
Alias: None
Product: udk
Classification: Code
Component: code (show other issues)
Version: OOo 2.0 Beta
Hardware: PC All
: P3 Trivial (vote)
Target Milestone: ---
Assignee: ab
QA Contact:
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-08-31 21:49 UTC by user967
Modified: 2017-05-20 09:24 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Latest Confirmation in: ---
Developer Difficulty: ---


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description user967 2005-08-31 21:49:53 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
Comment 1 kay.ramme 2005-09-02 17:17:08 UTC
Andreas, please have a look at this...
Comment 2 kay.ramme 2005-09-02 17:17:50 UTC
.
Comment 3 kay.ramme 2005-09-02 17:18:35 UTC
.
Comment 4 ab 2005-09-06 08:03:35 UTC
Started
Comment 5 ab 2006-08-25 07:53:16 UTC
STARTED
Comment 6 damjan 2015-12-16 14:37:47 UTC
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.