VB.NET 中 Try/catch 块的 GOTO

RRM*_*RRM 1 vb.net goto try-catch

是的,我知道 GOTO 是错误的,每次我使用它时,都会有一只小猫死掉;)还有一件事让我很好奇:

如果我在 try/catch 块中使用 GOTO 会怎样

Try
...some code...
Catch
...some code... 
  GoTo Label1
End Try
...some more code to be skipped if error
Label1:
...rest of code...
Run Code Online (Sandbox Code Playgroud)

我是否正确理解 try/catch 块永远不会在程序中关闭并且可能会导致问题?或不?

似乎还有一些 OnError GoTo 命令,但我对此没有太多经验。也许我的代码可以用它重写?

GSe*_*erg 6

我是否正确理解 try/catch 块永远不会关闭

不,try/catch 块将被关闭,因为您离开了它。跳出try/catch块是可以的

然而,代码应该重写为:

Try
  ...some code...
  ...some more code to be skipped if error
Catch
  ...some code... 
End Try

...rest of code...
Run Code Online (Sandbox Code Playgroud)