Article Options
Premium Sponsor
Premium Sponsor

 »  Home  »  Deployment  »  Installer Class and Custom Actions  »  Page 5
Installer Class and Custom Actions
by Arnaldo Sandoval | Published  10/15/2007 | Deployment | Rating:
Page 5

EXCEPTIONS AND EXCEPTION HANDLING IN YOUR INSTALLER CLASS

Your code in any Installer Class' event should handle any possible exception, if any exception is untrapped the application's whole installation or uninstallation process will fail; there is no way for the installation-uninstallation process to continue when your installer class raises an exception.

Sometimes anyone of the events in your installer class will find a no-go condition, a situation where you have to abort the process involved (Installation or Un-installation), what you do here is throwing an InstallException exception, using code like the one shown below:

Code:

throw new InstallException();


That's the most simple way to throw an Installer Class exception, so simple that it does not describe the error, giving the user installing your application no-clues regarding the error condition, so you should avoid this approach.

You may give the user more information when throwing the InstallException, with code like this one:

Code:

if (File.Exists("Test.txt") == false) 

   throw new InstallException("File does not exist!");
}


If the condition shown in the code above return a true value the "File does not exist!" will be thrown and the process involved will be cancelled; the user will get an screen like the one below:



Another way to throw an Installer Class' exception is while handling an exception, in this case you may want to include details of the real exception, like the code below illustrates:

Code:

try 
{ 
   throw new
IOException("Forcing an error");
}
catch
(Exception ex)
{ 
   throw new
InstallException("A forced exception", ex); 
}


It forces an IOException for illustration only, your own installer class event may throw its own exception due to the complexity of the code in execution, anyhow, in this case the installation or installation process will stop with a diplay like the one below:



As a feature of the Windows Installer module, any exception is recorded at the target machine's eventlog, you can use the Event Viewer (at the Control Panel's Administrative Tools.



Remember: any exception in your installer class will prevent your application's installation (or un-installation).

You may not like using exceptions to report installation issues with your application, perhaps you want to show a more friendly interface to your enduser at installation time, probably the error condition is not that critical to cancel the installation at all, in all these scenarios, you may want to show a friendly form to your user, allowing him/her to continue with the installation process.

 

Sponsored Links