InstallException Class

The exception that is thrown when an error occurs during the commit, rollback, or uninstall phase of an installation.

Namespace: System.Configuration.Install
Assembly: System.Configuration.Install (in system.configuration.install.dll)

'Declaration
<SerializableAttribute> _
Public Class InstallException
	Inherits SystemException
'Usage
Dim instance As InstallException

/** @attribute SerializableAttribute() */ 
public class InstallException extends SystemException
SerializableAttribute 
public class InstallException extends SystemException

The following example, plus the examples in the InstallException constructors, together make up an example showing an assembly having its own installer. The installer is named MyInstaller, which has an attribute RunInstallerAttribute, indicating that this installer will be invoked by Installer Tool (Installutil.exe). Installer Tool (Installutil.exe) calls the methods Commit, Rollback, Install and Uninstall. The code in Commit presumes that a file named FileDoesNotExist.txt exists before the installation of the assembly can be committed. If the file FileDoesNotExist.txt does not exist, Commit raises an InstallException. The same is the case with Uninstall in which an uninstallation will only happen if a file named FileDoesNotExist.txt exists. Otherwise it raises an InstallException. In Rollback, a code fragment is executed, which might raise an exception. If the exception is raised, it is caught and an InstallException is raised with that exception being passed to it.

NoteNote

Run this example with the help of Installutil.exe. Type this in the command prompt:

Installutil InstallException.exe

-or-

Installutil /u InstallException.exe

Imports System
Imports System.ComponentModel
Imports System.Collections
Imports System.Configuration.Install
Imports System.IO

<RunInstaller(True)> Public Class MyInstaller
   Inherits Installer

   Public Overrides Sub Install(savedState As IDictionary)
      MyBase.Install(savedState)
      Console.WriteLine("Install ...")

     ' Commit is called when install goes through successfully.
     ' Rollback is called if there is any error during Install.
     ' Uncommenting the code below will lead to 'RollBack' being called,
     ' currently 'Commit' shall be called.
     ' throw new IOException();

   End Sub

   Public Overrides Sub Commit(savedState As IDictionary)
      MyBase.Commit(savedState)
      Console.WriteLine("Commit ...")
      ' Throw an error if a particular file doesn't exist.
      If Not File.Exists("FileDoesNotExist.txt") Then
         Throw New InstallException()
      End If
      ' Perform the final installation if the file exists.
   End Sub

   Public Overrides Sub Rollback(savedState As IDictionary)
      MyBase.Rollback(savedState)
      Console.WriteLine("RollBack ...")
      Try
         ' Performing some activity during rollback that raises an 'IOException'.
         Throw New IOException()
      Catch e As Exception
         Throw New InstallException("IOException raised", e)
      End Try
   End Sub 'Rollback
    ' Perform the remaining rollback activites if no exception raised.

   Public Overrides Sub Uninstall(savedState As IDictionary)
      MyBase.Uninstall(savedState)
      Console.WriteLine("UnInstall ...")
      ' Throw an error if a particular file doesn't exist.
      If Not File.Exists("FileDoesNotExist.txt") Then
         Throw New InstallException("The file 'FileDoesNotExist'" + " does not exist")
      End If
      ' Perform the uninstall activites if the file exists.
   End Sub

End Class

' An Assembly that has its own installer.
Public Class MyAssembly1
   Public Shared Sub Main()
      Console.WriteLine("This assembly is just an example for the Installer")
   End Sub
End Class

import System.*;
import System.ComponentModel.*;
import System.Collections.*;
import System.Configuration.Install.*;
import System.IO.*;

/** @attribute RunInstaller(true)
 */
public class MyInstaller extends Installer
{
    public void Install(IDictionary savedState)
    {
        super.Install(savedState);
        Console.WriteLine("Install ...");
     //Install

    // Commit is called when install goes through successfully.
    // Rollback is called if there is any error during Install.
    // Uncommenting the code below will lead to 'RollBack' being called,
    // currently 'Commit' shall be called.
    // throw new IOException();
    public void Commit(IDictionary savedState) 
        throws System.Configuration.Install.InstallException   
    {
        super.Commit(savedState);
        Console.WriteLine("Commit ...");

        // Throw an error if a particular file doesn't exist.
        if (!(File.Exists("FileDoesNotExist.txt"))) {
            throw new InstallException();
        
        // Perform the final installation if the file exists.
     //Commit
    public void Rollback(IDictionary savedState) 
        throws System.Configuration.Install.InstallException   
    {
        super.Rollback(savedState);
        Console.WriteLine("RollBack ...");
        try {
            // Performing some activity during rollback 
            //that raises an 'IOException'.
            throw new IOException();
        
        catch (System.Exception e) {
            throw new InstallException("IOException raised", e);
        
        // Perform the remaining rollback activites if no exception raised.
     //Rollback
    public void Uninstall(IDictionary savedState) 
        throws System.Configuration.Install.InstallException   
    {
        super.Uninstall(savedState);
        Console.WriteLine("UnInstall ...");

        // Throw an error if a particular file doesn't exist.
        if (!(File.Exists("FileDoesNotExist.txt"))) {
            throw new InstallException("The file 'FileDoesNotExist'" 
                + " does not exist");
        
     //Uninstall
 //MyInstaller
 // Perform the uninstall activites if the file exists.

// An Assembly that has its own installer.
public class MyAssembly1
{
    public static void main(String[] args)
    {
        Console.WriteLine("This assembly is just an example for the Installer");
     //main
 //MyAssembly1

System.Object
   System.Exception
     System.SystemException
      System.Configuration.Install.InstallException

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show: