It's not blowing up, it's telling me that the error is unhandled. i.e. My routine that it bubbles up to is not bothering to catch it, so that it eventually bubbles all the way up to the IDE - where it's reported as unhandled. Which is what it's supposed to do when I don't bother catching it, right
Correct - you still should handle the error in a try-catch block somewhere. For example the following code displays the message box when you click the button. If you called the CatchAndThrowError method without the Try-Catch you will get the unhandled exception
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Try CatchAndThrowError() Catch ex As Exception MsgBox("caught in the click") End Try
End Sub
Private Sub CatchAndThrowError() Dim i As Integer = 1 Dim s As String = "Foo" Try i = s Catch ex As Exception Throw ex End Try End Sub
rethrowing an error
Dan DeLaf
Catch err As Exception
Throw New Exception(err.Message)
End Try
Dustin.
Tom Dixon
I looks very odd.
It would be helpful to see the problem if you post some real code.
Brachole
It's not blowing up, it's telling me that the error is unhandled. i.e. My routine that it bubbles up to is not bothering to catch it, so that it eventually bubbles all the way up to the IDE - where it's reported as unhandled. Which is what it's supposed to do when I don't bother catching it, right
I'm still learning this stuff.
C2O
What version are you running
I just tried this and the exception gets thrown as expected
Private Sub CatchAndThrowError()
Dim i As Integer = 1
Dim s As String = "Foo"
Try
i = s
Catch ex As Exception
Throw ex
End Try
End Sub
PWStevens
PCM2
No really, I just want the general syntax for now. All I want to do is allow my exception to bubble up to my top layer.
turbofreddan
Correct - you still should handle the error in a try-catch block somewhere.
For example the following code displays the message box when you click the button. If you called the CatchAndThrowError method without the Try-Catch you will get the unhandled exception
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
CatchAndThrowError()
Catch ex As Exception
MsgBox("caught in the click")
End Try
End Sub
Private Sub CatchAndThrowError()
Dim i As Integer = 1
Dim s As String = "Foo"
Try
i = s
Catch ex As Exception
Throw ex
End Try
End Sub
hope that helps...