ayozzhero
Well-known member
To catch any errors in my app which is not within the Try...Catch...End Try block, I put this in the Sub Main:
which redirects the error to:
I want to trap a specific error, e.g. Divide by Zero. In OnThreadException I will handle the error, i.e. resetting to Zero value to one. Then, I want to return to the same function/code that generates the error and run it back again (this time there should be no more Divide by Zero error because I already reset the variable value). Can I do this in VB .Net?
Thank you for helping.
VB.NET:
[color=Blue]AddHandler [/color]Application.ThreadException, [color=Blue]AddressOf [/color]OnThreadException
which redirects the error to:
VB.NET:
[color=black][color=Blue]Private Sub[/color] OnThreadException([color=Blue]ByVal [/color]sender [color=Blue]As Object[/color], _
[color=Blue]ByVal [/color]e [color=Blue]As [/color]ThreadExceptionEventArgs)
[color=Blue]Try[/color]
ErrorMessage = "Error Description:" & vbCrLf & e.Exception.Message.ToString & _
vbCrLf & vbCrLf & _
"Other Info: " & vbCrLf & _
e.Exception.ToString & vbCrLf
[color=Blue]Catch [/color]ex [color=Blue]As Exception[/color]
ErrorMessage = "Error Description:" & vbCrLf & "Unknown Error"
[color=Blue]Finally[/color]
[color=Blue]Dim [/color]oForm [color=Blue]As New[/color] frmErrorCapture
oForm.Show()
[color=Blue]End Try[/color]
[color=Blue]End Sub[/color][/color]
I want to trap a specific error, e.g. Divide by Zero. In OnThreadException I will handle the error, i.e. resetting to Zero value to one. Then, I want to return to the same function/code that generates the error and run it back again (this time there should be no more Divide by Zero error because I already reset the variable value). Can I do this in VB .Net?
Thank you for helping.