Catching FileNotFoundException

  • Thread starter Thread starter Kevin Burton
  • Start date Start date
K

Kevin Burton

I have a C++ .NET wrapper for some functions that depends
on a particular DLL. If that software is not installed I
would like to be able to gracefully handle the situation
rather than be prompted that the DLL/assembly or one of
it's dependencies could not be found. I tried to 'catch'
the FileNotFoundException but my catch seems to be
ignored. Does anyone know how I can acheive this
functionality?

Thank you.

Kevin
 
Thus spake Kevin Burton:
Does anyone know how I can acheive this functionality?

Can't you check for the existence of the DLL at startup and disable the
dependent functionality if it's missing?
 
I thought about that but it could be problematic to find
the path the the dependent DLL(s). They could be installed
anywhere. I know I could just go through the path and se
if I find it but that seems like too much work. I would
rather just catch an exception and report it. It seems so
much easier (if it can be done).

Kevin
 
Thus spake Kevin Burton:
I thought about that but it could be problematic to find
the path the the dependent DLL(s). They could be installed
anywhere.

So these are not COM servers? Can't you just redistribute the DLLs in
that case?
I know I could just go through the path and se
if I find it but that seems like too much work. I would
rather just catch an exception and report it. It seems so
much easier (if it can be done).

From a user standpoint, not being able to use a given feature is much
more intuitive than receiving an error message when trying to use that
feature.
 
If you're missing a dependant DLL, I would have expected you would get a
type load exception, not a file not found. Have you confirmed the type of
exception you get?
 
But I need to tell if software is installed. For licensing
reasons I cannot just redistribute the DLL(s). And, I
don't want the whole application to be disabled because
this software has not been installed (which is the default
action when a DLL is missing).

Kevin
 
The default action is that I get a dialog box from the CLR
(JIT) indicating that an uncaught exception
FileNotFoundException was thrown. I want to get rid of
this dialog box so the user of my application does not
have to understand or care that this DLL(s) are present or
absent.

Kevin
 
I had the same problem.

You would think that you could simply take the one statement that
creates an instance of the wrapper class and enclose it in a try block.
Then to simply catch the FileNotFoundException.

But no.

I had to take the instance statement and put it in another function.
Then I put the call to this separate function in the try block. I don't
know why this had to be done but after that the exception handler
worked.
 
Back
Top