I’m attempting to handle login errors before advancing to the next form and, for the most part, everything is working. I am having one problem – when the network connection is not established, the ODBC driver provides its own ugly error message.
Here’s my code:
Try
ODBCconnection.Open()
ODBCconnection.Close()
Me.Hide()
otherForm.ShowDialog()
Catch ex As Exception
If ex.Message.IndexOf("ugly network problem message") > -1 Then
MsgBox("fancy network problem message")
ElseIf ex.Message.IndexOf("other error message") > -1 Then
MsgBox("fancy other error message")
End If
End Try
So, if “other error message” is caught, it shows “fancy other error message”, but if “ugly network problem message” is caught, it shows both the ugly and the fancy error messages.
My thought it that the driver itself is generating a message, any ideas on how to suppress it?
You will need to handle that specific ODBC exception before handling the
System.Exceptionexception.To Answer your question about the specifics…
The rule is that your exception handling must flow from more to less specific or from derived Exception classes to their base classes all the way back to
System.Exception. In other words, if you have any specific exceptions to handle you must handle those before you handle theSystem.Exceptionexception…In Visual Studio exception helper that pops up when you place a break point in your
Catch ex As Exceptionblock you can see exactly what is the exception that is being thrown and that is the exception that you must catch before yourCatch ex As Exceptionblock…As you can see from the screenshot the VS exception helper displays the exact name of the Exception and if you click on ‘View Detail’ you get a window with many more details including the full namespace of the exception that occurred… have you ever seen this Exception Helper or are you using some other IDE?