Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exceptions

Status
Not open for further replies.

VBAHole22

Programmer
Nov 7, 2002
41
US
I have a snippet of code that builds a command button for use in another program. I am using a bitmap image for the icon of this button. If I spell the name of the bitmap image incorrectly it doesn't work.
So I set up a Try Catch block to catch this. It works but the trouble I am having now is that it is a generic catch block (just the word Catch). I would like to setup a specific Catch block (like Catch e as System.DivideByZeroException) but I don't know the specific exception I am trapping in this case.
If I Catch the error shouldn't I be able to figure out what the error was? When I use e.Message I get :

'null' is not a valid value for 'stream'

The calling code is :

Try
Dim strPath As String = "ArcGIS_ll.happy1.bmp"
m_bitmap = New System.Drawing.Bitmap((Me.GetType.Assembly.GetManifestResourceStream(strPath)))
' Throw New BogusImageFilePath(strPath)
Catch e As System.Exception
Debug.WriteLine("Bogus image file", e.Message)
' Throw New BogusImageFilePath(strPath)
End Try

How can I setup a more refined Catch statement so that I will know if a different error has occured?
 
Use e.GetType, this will return the exception type.
 
I see that there is a GetType method but how can I expose it? When I try

Debug.WriteLine("type is",e.GetType)

I get error saying it can't convert GetType to string?
 
GetType returns a datatype called Type (part of the framework - see MSDN). You would then have to call the .ToString() method on the Type object. Your code should look like:
Code:
Debug.WriteLine("type is",e.GetType.ToString())
Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top