c# - 出错时转到 ErrHand(C#)

标签 c# error-handling

在 C# 中,如果我有错误,我如何将它发送到错误处理行,如下所示。我知道如何在 Visual Basic 中执行此操作,但在 C# 中需要一点帮助。感谢您的帮助

Sub Main()
On Error GoTo ErrHand
....Code Here
End Sub

ErrHand:
  MsgBox "Message Here"
End Sub

最佳答案

On Error GoTo 模式在 .NET 中升级为:

try
{
   // Execute your code
}
catch  <ExceptionType>
{
 // Handle exception
}
finally
{
 // Cleanup resources
}

以下链接Error Handling Transformation应该给你一些信息。

关于c# - 出错时转到 ErrHand(C#),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7876081/

相关文章:

iphone - 无法追踪错误

r - 为什么我使用naiveBayes函数会得到未定义的列?

android - Android Studio 未找到默认 Activity 错误

c# - novacode docx 中的垂直表格无边框

java - 在Java中检查输入是5、10、15、20、25还是30

c# - 在asp.net mvc 5中创建可编辑的cshtml View 页面

c# - Global.asax 中的 Server.Transfer

error-handling - 了解Erlang ODBC应用程序

c# - 无法将数据写入传输连接 : An existing connection was forcibly closed by the remote host

c# - 机器人框架 v4 : ReplaceDialogAsync A dialog with an id of 'X' wasn't found