簡體   English   中英

錯誤處理程序中的錯誤處理

[英]Error handling in Error handler

我正在使用以下代碼,當用戶單擊輸入框中的取消按鈕時,錯誤處理程序正在處理錯誤。

但是如果錯誤處理程序中再次出現錯誤,則錯誤處理程序不會處理該錯誤。

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

我應該在代碼中進行哪些更改來處理錯誤處理程序中生成的錯誤?

您必須重置錯誤處理程序,然后設置一個新的:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM