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

标签 vb.net exception

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

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/

相关文章:

java - 线程为自己抛出 InterruptedException 是否正确?

c++ - 在包含 std::string 的函数上使用 throw() 后缀是否安全?

vb.net - 确定谁阅读了共享邮箱中的邮件

vb.net - Visual Basic 模块 v 单例

c# - 将 VB.NET 项目转换为 C# 项目

java - 在这种情况下如何保留堆栈跟踪?

java - 如何在 Java 中记录未捕获的异常?

SQL Server 'Resume Next' 等效项

c++ - 如何在 Visual Basic DLL 和 C++ DLL 之间创建隔离/免注册 COM?

c++:从析构函数中抛出异常