Freigeben über


InstallException-Klasse

Die Ausnahme, die ausgelöst wird, wenn während der Commit-, Rollback- oder Deinstallationsphase einer Installation ein Fehler auftritt.

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

Syntax

'Declaration
<SerializableAttribute> _
Public Class InstallException
    Inherits SystemException
'Usage
Dim instance As InstallException
[SerializableAttribute] 
public class InstallException : SystemException
[SerializableAttribute] 
public ref class InstallException : public SystemException
/** @attribute SerializableAttribute() */ 
public class InstallException extends SystemException
SerializableAttribute 
public class InstallException extends SystemException

Beispiel

Das folgende Beispiel zeigt zusammen mit den Beispielen in den InstallException-Konstruktoren eine Assembly mit ihrem eigenen Installationsprogramm. Das Installationsprogramm hat den Namen MyInstaller und verfügt über das Attribut RunInstallerAttribute, mit dem angegeben wird, dass dieses Installationsprogramm durch Installer-Tool (Installutil.exe) aufgerufen wird. Installer-Tool (Installutil.exe) ruft die Methoden Commit, Rollback, Install und Uninstall auf. Im Code von Commit wird vorausgesetzt, dass die Datei FileDoesNotExist.txt vorhanden ist, bevor ein Commit der Assemblyinstallation ausgeführt werden kann. Wenn die Datei FileDoesNotExist.txt nicht vorhanden ist, löst Commit eine InstallException aus. Dies gilt ebenfalls für Uninstall, bei dem eine Deinstallation nur dann stattfindet, wenn eine Datei mit dem Namen FileDoesNotExist.txt vorhanden ist. Andernfalls wird eine InstallException ausgelöst. In Rollback wird ein Codefragment ausgeführt, durch das eine Ausnahme ausgelöst werden kann. Wird die Ausnahme ausgelöst, wird sie abgefangen, und es wird eine InstallException ausgelöst, an die diese Ausnahme übergeben wird.

Hinweis

Führen Sie dieses Beispiel mithilfe von Installutil.exe aus. Geben Sie an der Eingabeaufforderung Folgendes ein:

Installutil InstallException.exe

– oder –

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
using System;
using System.ComponentModel;
using System.Collections;
using System.Configuration.Install;
using System.IO;


[RunInstaller(true)]
public class MyInstaller : Installer
{
   public override void Install(IDictionary savedState)
   {
      base.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();
   }

   public override void Commit(IDictionary savedState)
   {
      base.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.
   }

   public override void Rollback(IDictionary savedState)
   {
      base.Rollback(savedState);
      Console.WriteLine("RollBack ...");
      try
      {
         // Performing some activity during rollback that raises an 'IOException'.
         throw new IOException();
      }
      catch(Exception e)
      {
         throw new InstallException("IOException raised", e);
      }
      // Perform the remaining rollback activites if no exception raised.
   }

   public override void Uninstall(IDictionary savedState)
   {
      base.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");
      // Perform the uninstall activites if the file exists.
   }
}


// An Assembly that has its own installer.
public class MyAssembly1
{
   public static void Main()
   {
      Console.WriteLine("This assembly is just an example for the Installer");
   }
}
#using <System.dll>
#using <System.Configuration.Install.dll>

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Configuration::Install;
using namespace System::IO;

[RunInstaller(true)]
ref class MyInstaller: public Installer
{
public:
   virtual void Install( IDictionary^ savedState ) override
   {
      Installer::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();
   }


   virtual void Commit( IDictionary^ savedState ) override
   {
      Installer::Commit( savedState );
      Console::WriteLine( "Commit ..." );
      
      // Throw an error if a particular file doesn't exist.
      if (  !File::Exists( "FileDoesNotExist.txt" ) )
            throw gcnew InstallException;

      
      // Perform the final installation if the file exists.
   }


   virtual void Rollback( IDictionary^ savedState ) override
   {
      Installer::Rollback( savedState );
      Console::WriteLine( "RollBack ..." );
      try
      {
         
         // Performing some activity during rollback that raises an 'IOException*'.
         throw gcnew IOException;
      }
      catch ( Exception^ e ) 
      {
         throw gcnew InstallException( "IOException* raised",e );
      }

      
      // Perform the remaining rollback activites if no exception raised.
   }


   virtual void Uninstall( IDictionary^ savedState ) override
   {
      Installer::Uninstall( savedState );
      Console::WriteLine( "UnInstall ..." );
      
      // Throw an error if a particular file doesn't exist.
      if (  !File::Exists( "FileDoesNotExist.txt" ) )
            throw gcnew InstallException( "The file 'FileDoesNotExist'  does not exist" );

      
      // Perform the uninstall activites if the file exists.
   }

};

int main()
{
   Console::WriteLine( "This assembly is just an example for the Installer" );
}
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

Vererbungshierarchie

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

Threadsicherheit

Alle öffentlichen statischen (Shared in Visual Basic) Member dieses Typs sind threadsicher. Bei Instanzmembern ist die Threadsicherheit nicht gewährleistet.

Plattformen

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

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

InstallException-Member
System.Configuration.Install-Namespace
Commit
Installer-Klasse
Rollback
Uninstall