[RESOLVED] getIcon func exceptions
hey
I'm getting many exceptions relating to:
Code:
Public Function getIcon(ByVal path As String) As Icon
Try
Return System.Drawing.Icon.ExtractAssociatedIcon(path)
Catch ex As System.Exception
Return Nothing
End Try
End Function
exceptions:
Code:
A first chance exception of type 'System.IO.FileNotFoundException' occurred in System.Drawing.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in System.Drawing.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in System.Drawing.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in System.Drawing.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in System.Drawing.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in System.Drawing.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in System.Drawing.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in System.Drawing.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in System.Drawing.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in System.Drawing.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in System.Drawing.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in System.Drawing.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in System.Drawing.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in System.Drawing.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in System.Drawing.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in System.Drawing.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in System.Drawing.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in System.Drawing.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in System.Drawing.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in System.Drawing.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in System.Drawing.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in System.Drawing.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in System.Drawing.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in System.Drawing.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in System.Drawing.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in System.Drawing.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in System.Drawing.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in System.Drawing.dll
Please can someone help solve?
Re: getIcon func exceptions
...well...do you see what the Exception tells you? It says FileNotFoundException which means the path you're giving the function is invalid! So why don't you work on showing what the path is when an exception is thrown instead of ignoring and returning nothing! You might as well have put
Code:
On Error Resume Next
in your function as that's essentially what you're doing.
Note that I linked you to MSDN for the exception. You should ALWAYS consult the documentation if you don't understand what's going on. I literally went to Bing (it even works the same on Google and Yahoo! as well) and typed in "System.IO.FileNotFoundException" and the MSDN library was the first result.
Re: getIcon func exceptions
Re: getIcon func exceptions
Yes it works if the filepath points to a file that actually exists. What I don't understand is how you're getting errors with the Try/Catch in place to ignore them!
Re: getIcon func exceptions
Quote:
Originally Posted by
formlesstree4
...well...do you see what the Exception tells you? It says
FileNotFoundException which means the
path you're giving the function is invalid! So why don't you work on showing what the path is when an exception is thrown instead of ignoring and returning nothing! You might as well have put
Code:
On Error Resume Next
in your function as that's essentially what you're doing.
Note that I linked you to MSDN for the exception. You should ALWAYS consult the documentation if you don't understand what's going on. I literally went to Bing (it even works the same on Google and Yahoo! as well) and typed in "System.IO.FileNotFoundException" and the MSDN library was the first result.
Yo don't u think i'd already researched it, that "on error resume next" is no use, with the try and catch........
Re: getIcon func exceptions
Quote:
Originally Posted by
dunfiddlin
Yes it works if the filepath points to a file that actually exists. What I don't understand is how you're getting errors with the Try/Catch in place to ignore them!
exceptions bud, no erros...........
Re: getIcon func exceptions
Re: getIcon func exceptions
Quote:
Originally Posted by
chris-2k
exceptions bud, no erros...........
Well any exceptions caught by a try-catch are shown in the immediate window, if that is what you mean that is normal.
Re: getIcon func exceptions
Quote:
Originally Posted by
Edgemeal
Well any exceptions caught by a try-catch are shown in the immediate window, if that is what you mean that is normal.
Yea it is, so the exceptions are only there when something is wrong...
How can i see what value path is holding?
Re: getIcon func exceptions
My brother dcrew fixed it, thanks for trying to help though.
Code:
Public Function getIcon(ByVal path As String) As Icon
If (File.Exists(path)) Then Return System.Drawing.Icon.ExtractAssociatedIcon(path)
Return Nothing
End Function
edit: it was also another piece of code that needed fixing, he fixed though.