Home > Software engineering >  On Error Goto to a function within two consecutive Error. What should I do?
On Error Goto to a function within two consecutive Error. What should I do?

Time:10-05

For the On Error Goto statement
In the MSDN is so explain:
If the error handler is active (in errors and executive Resume, Exit Sub, Exit Function or Exit Property statements between this period of time) and an error occurs, the current process of the fault handler will not be able to deal with this error,
If the problem is that I need to use many times continuously is needed in a function On errorGoto statements for error conditions when jump, can't jump, in accordance with the requirements of the second start results such as the original code is as follows:
On error Goto Lable1
1 'statements 1-3 processing object, may be because of the different attributes of object 1 error, error when want to jump to the statement, 11 starts processing object 2
Statements 1
Statements 2
Statement 3
Lable1:
On error goto Lable2
'11-13 statement object 2, may be because the different attributes of objects 2 and error
Statement 11
Statement of 12
Statement 13
Lable2:
On error goto Lable3
'statement 21-23 processing object 3, may be because the different attributes of objects 3 and error
Statement 21
Statement of 22
A statement 23
* * * * * * * * * * * * * * * * * * * * * * * *
The overall train of thought:
Is when the processing object 1 if an error, then jump to the processing object 2, if handled object 2 error, will jump to the object 3,
But the problem is that the On error goto statements after processing error for the first time, subsequent to no matter use, when the object 1 error after the jump,
Can't handle object 2 error jump, the entire program is stuck in there,
Excuse me everybody, want how to deal with,
Deal with each object's situation is more complex, so can't prejudge where could go wrong, might be wrong, of course,
the condition of theAs much as possible in the program are given,
Such a logic structure to how to deal with, thank you.

CodePudding user response:

You write under the label1
Err. Clear give it a try

CodePudding user response:

Can consider appropriately on the error resume next...

CodePudding user response:

reference 1st floor clear_zero response:
you write under the label1
Err. Try the clear


Tried, did not use the
Err. Clear can the err of value to zero, but can't seem to interruption of its internal mechanism to reset

CodePudding user response:

refer to the second floor Topc008 response:
can consider appropriately on the error resume next...

Also considered this writing,
Combined with the if (err) num & lt;> 0) then...
The else...
Such wording, but ability is limited, there has been no thought of the final method

CodePudding user response:

The individual feels there is no need to deal with all the potential mistakes...

CodePudding user response:

 Private Sub Command1_Click () 
Dim iProgress As Long 'to distinguish the different steps
Dim obj1 As Object
Dim obj2 As Object
Dim obj3 As Object
Dim As Long I

On Error GoTo ErrHandler

IProgress=1
I=100/obj1. Length

Step2:
IProgress=2
The Set obj2=New Collection
I=100/obj2. Length

Step3:
IProgress=3
The Set obj3=New Collection
I=100/obj3. Count

MsgBox "is finally successful!"

ExitEntry:
The Exit Sub
ErrHandler:
The Debug. Print iProgress, Err. Number, Err. The Description
The Select Case iProgress
Case 1
Resume Step2
Case 2
Resume Step3
End the Select
MsgBox "all wrong!"
Resume ExitEntry
End Sub

CodePudding user response:

Add On Error Goto 0 or Resume

CodePudding user response:

 
Option Explicit

Private Sub Command1_Click ()


On Error GoTo l2

L1:
The Debug. Print "l1"
The Debug. Print 1/0
The Exit Sub
L2:
On Error GoTo - 1
On Error GoTo l3
The Debug. Print "l2"
The Debug. Print 1/0
The Exit Sub

L3:
On Error GoTo - 1
On Error GoTo l3

The Debug. Print "l3
"The Debug. Print 1/0

Stop

End Sub



CodePudding user response:

On the error resume next + err. Number value judgment, for example:

On the error resume next
Statements 1
If err. Number<> 0 then
Err. Clear
Goto label1
End the if
Statements 2
If err. Number<> 0 then
Err. Clear
Goto label1
End the if
.
Goto exitlabel
Label1:
Statement 11
If err. Number<> 0 then
Err. Clear
Goto label2
End the if
Statement of 12
If err. Number<> 0 then
Err. Clear
Goto label2
End the if
.
Exitlabel:

CodePudding user response:

# 6 right, in addition, the question I was also special post explained:
http://bbs.csdn.net/topics/390803908
Recommended] [share] [original technology VB6 error handling in order (with multiple error handling in the process)

CodePudding user response:

In the Error handling calls another Sub, again On the Error in the Sub

CodePudding user response:


Examples of handling errors in the error,,,
However, this is will have objection to

 
Option Explicit


Private Sub Command1_Click ()

L1:
On Error GoTo - 1
On Error GoTo l2

The Debug. Print "l1"
The Debug. Print 1/0
The Exit Sub
L2:
On Error GoTo - 1
On Error GoTo l3
The Debug. Print "l2"
The Debug. Print 1/0
The Exit Sub

L3:
On Error GoTo - 1
On Error GoTo l4

The Debug. Print "l3
"The Debug. Print 1/0

L4:
On Error GoTo - 1
On Error GoTo l5

The Debug. Print "l4"
The Debug. Print 1/0

L5:
On Error GoTo - 1
On Error GoTo l1

The Debug. Print "l5
"The Debug. Print 1/0

Stop

End Sub

CodePudding user response:

On error are meant to be you debug source use, consider it carefully, to write robust code, there will be no you this kind of problem.

CodePudding user response:

11 references zhao4zhong1 response:
in Error handling calls another Sub, again On the Error in this Sub

Positive solution! nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related