I am trying to do some error handling while also initializing new classes. I'm surprised at the way it is set up and am hoping that I'm just missing something very simple. Here's a simple version of what I'm trying to accomplish:
Public Class TestClass
Public Sub New(ByVal sLink as String)
Try
Me.New(New Uri(sLink))
Catch ex As Exception
MessageBox.Show("Hey, initializing this class failed... Is the URL valid?")
End Try
End Sub
Public Sub New(ByVal uLink as Uri)
MessageBox.Show("Class Initialized Successfully!")
End Sub
End Class
The above obviously fails because the line with "Me.New(...)" must be the first line. I could do that however, what if somebody passes a string that is not a valid Uri? Consider the following:
' This would fail and I'd like to catch it somehow
Dim tmp as New TestClass("Hello World!")
' Something like this would pass successfully
Dim tmp as New TestClass("http://somevalidlink.com/")
' And so would this, too.
Dim tmp as New TestClass(New Uri("http://somevalidlink.com/")
I have been searching and can't seem to find anything... Maybe I just don't know the keywords to look for. Any hints in the right direction would be a great help.
Thanks!