I'm not familiar with the library you are using but any exception due to an invalid file will originate from the MyWinPlayer.Open()
method (function in vb-speak). So if an exception is thrown, you need to handle that exception inside of a try-catch. If your current sub does not handle the exception, then the exception will bubble up to the calling method and keep going until there is some place that the exception is handled.
A try-catch block would be something like this (I don't write a lot in vb.net anymore, the syntax may not be perfect):
Try
mPlayer.Open(filename);
Catch ex As Exception
'Do something with the exception
' (e.g. write a log, set a value, or display error message)
End Try
Despite what I have written in the code block above, I would encourage you not to catch a general Exception
, and instead focus on the specific type of exception that could be thrown from the Open()
method. The reason is you only want to handle exceptions that you know how to handle in the current method and let the other exceptions bubble up. You would need to look at the documentation for the library and see what type of exceptions could be throw and include them.
Another important thing to mention is unless you have a very good reason, do not use an empty catch
block (I can't think of one at the moment, but I'm sure there are some very rare uses). An empty catch
will just swallow the exception and not do anything with it. It won't even notify you that there was an exception.
Now if you don't handle any exception, the exception should bubble up all the way to the top of the call stack and the debugger should show an Unhandled Exception
message and stop there. If it is not doing that then either you are swallowing the exception further down the call stack or you are running into the bug that is mentioned in the possible duplicate Hans Passant mentioned in his comment
MSDN has a pretty decent summary of exception handling in the .NET languages. I would encourage you to read more on the subject.