【发布时间】:2012-11-16 02:38:29
【问题描述】:
我正在使用 VS2012 VB.net。
我能否帮助我创建一些代码来计算异常的错误行以及发生异常的函数。
这是我当前的代码:
Partial Friend Class MyApplication
Public exceptionListOfExceptionsToNotPauseOn As New List(Of ApplicationServices.UnhandledExceptionEventArgs)
Private Sub MyApplication_UnhandledException(sender As Object, e As ApplicationServices.UnhandledExceptionEventArgs) Handles Me.UnhandledException
Dim msgboxResult As MsgBoxResult
Dim booleanExceptionFoundInList As Boolean = False
'Dim trace As System.Diagnostics.StackTrace = New System.Diagnostics.StackTrace(ex, True)
'Dim exceptionLineNumber = trace.GetFrame(0).GetFileLineNumber()
For x = 0 To exceptionListOfExceptionsToNotPauseOn.Count - 1
If exceptionListOfExceptionsToNotPauseOn(x).Exception.Message = e.Exception.Message Then
booleanExceptionFoundInList = True
End If
Next
If Not booleanExceptionFoundInList Then
msgboxResult = MessageBox.Show("An exception error has occured." & vbCrLf & "Error message: " & e.Exception.Message & vbCrLf & "Do you wish to pause on this exception again?", "Exception", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)
If msgboxResult = Microsoft.VisualBasic.MsgBoxResult.No Then
exceptionListOfExceptionsToNotPauseOn.Add(e)
End If
End If
e.ExitApplication = False
End Sub
End Class
更新
跟踪代码的代码使用异常数据类型,其中处理上述未处理异常的代码具有“e As ApplicationServices.UnhandledExceptionEventArgs”参数。我可以使用这种数据类型的跟踪代码吗?我需要将其转换为异常类型吗?还是不可能?
【问题讨论】:
-
你是如何追踪这个异常的?希望没有消息是好消息,因为它仍然是调试器可以捕获的第一次机会异常。也许回到源代码管理,看看在问题开始发生时对导致问题的特定函数进行了哪些代码更改。
标签: vb.net function exception-handling visual-studio-2012 line-numbers