error handling程序中的error handling

我正在使用下面的代码,当用户在input框中单击取消button时,error handling程序正在处理错误。

但是,如果在error handling程序中再次出现错误,那么error handling程序不会处理该错误。

Sub calculateroot() Dim msg As String, t as Integer On Error GoTo myhandle Dim inp As Integer, sql As Single inp = InputBox("Enter the number to find the square root") sql = Sqr(inp) Exit Sub myhandle: t = InputBox("Is this recursive ?") End Sub 

我应该在代码中进行哪些更改以处理error handling程序中生成的错误?

您必须重置error handling程序,然后设置一个新的:

 Sub calculateroot() Dim msg As String, t As Integer On Error GoTo myhandle Dim inp As Integer, sql As Single inp = inputbox("Enter the number to find the square root") sql = Sqr(inp) Exit Sub myhandle: On Error GoTo -1 On Error GoTo myhandle2 t = inputbox("Is this recursive ?") MsgBox t Exit Sub myhandle2: MsgBox "myhandle2" End Sub 

如果你需要恢复,这个恶心的代码工作:

 On Error Resume Next parm = "bla" DoSomething(parm) If Err.Number > 0 Then Err.Clear parm = "oldbla" DoSomething(parm) End If If Err.Number > 0 Then Err.Clear parm = "evenolderbla" DoSomething(parm) End If