gpt4 book ai didi

vb.net - 抛出异常后如何继续运行代码?

转载 作者:行者123 更新时间:2023-12-03 00:52:01 28 4
gpt4 key购买 nike

我想知道是否有办法让程序在抛出异常后继续执行。例如:

Try
line 1
line 2
line 3
line 4 ' (here the exception is thrown and jumps to the catch)
line 5 ' <-- I would like the program to continue its execution, logging the error
line 6

Catch ex as Exception
log(ex.tostring)
End Try

最佳答案

如果您正在做一些知道如何恢复或不重要的事情,则应该使用特定的 catch 将该行包装在 try/catch 中。例如

Try 
line 1
line 2
line 3
Try
line 4 ' (here the exception is throw and jumps to the catch)
Catch iox as IOException ' or whatever type is being thrown
'log it
End Try
line 5 ' <-- I would like the program to continue its execution after logging the error
line 6

Catch ex as Exception
log(ex.tostring)
End Try

关于vb.net - 抛出异常后如何继续运行代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3366635/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com