InstallException Klasse

Definition

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

public ref class InstallException : SystemException
[System.Serializable]
public class InstallException : SystemException
[<System.Serializable>]
type InstallException = class
    inherit SystemException
Public Class InstallException
Inherits SystemException
Vererbung
InstallException
Attribute

Beispiele

Das folgende Beispiel sowie die Beispiele in den InstallException Konstruktoren bilden zusammen ein Beispiel für eine Assembly mit einem eigenen Installationsprogramm. Das Installationsprogramm heißt MyInstaller, das über ein Attribut RunInstallerAttributeverfügt, das angibt, dass dieses Installationsprogramm von Installutil.exe (Installer Tool) aufgerufen wird. Installutil.exe (Installer Tool) ruft die Methoden Commit, Rollbackund InstallUninstall. Der Code in Commit der Annahme, dass eine Datei mit dem Namen FileDoesNotExist.txt vorhanden ist, bevor die Installation der Assembly zugesichert werden kann. Wenn die Datei FileDoesNotExist.txt nicht vorhanden ist, Commit wird ein InstallException. Dasselbe ist der Fall, bei Uninstall dem eine Deinstallation nur auftritt, wenn eine Datei mit dem Namen FileDoesNotExist.txt vorhanden ist. Andernfalls wird ein InstallException. In Rollback, wird ein Codefragment ausgeführt, das eine Ausnahme auslösen kann. Wenn die Ausnahme ausgelöst wird, wird sie abgefangen und mit InstallException dieser Ausnahme ausgelöst, die an sie übergeben wird.

Note

Führen Sie dieses Beispiel mithilfe von Installutil.exeaus. Geben Sie dies in die Eingabeaufforderung ein:

Installutil InstallException.exe

-oder-

Installutil /u InstallException.exe

#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" );
}
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");
   }
}
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
    ' 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

Konstruktoren

Name Beschreibung
InstallException()

Initialisiert eine neue Instanz der InstallException-Klasse.

InstallException(SerializationInfo, StreamingContext)

Initialisiert eine neue Instanz der InstallException Klasse mit serialisierten Daten.

InstallException(String, Exception)

Initialisiert eine neue Instanz der InstallException Klasse und gibt die Meldung an, die dem Benutzer angezeigt werden soll, und einen Verweis auf die innere Ausnahme, die die Ursache dieser Ausnahme ist.

InstallException(String)

Initialisiert eine neue Instanz der InstallException Klasse und gibt die Meldung an, die dem Benutzer angezeigt werden soll.

Eigenschaften

Name Beschreibung
Data

Ruft eine Auflistung von Schlüssel-Wert-Paaren ab, die zusätzliche benutzerdefinierte Informationen zur Ausnahme bereitstellen.

(Geerbt von Exception)
HelpLink

Dient zum Abrufen oder Festlegen eines Links zur Hilfedatei, die dieser Ausnahme zugeordnet ist.

(Geerbt von Exception)
HResult

Dient zum Abrufen oder Festlegen von HRESULT, einem codierten numerischen Wert, der einer bestimmten Ausnahme zugewiesen ist.

(Geerbt von Exception)
InnerException

Ruft die Exception Instanz ab, die die aktuelle Ausnahme verursacht hat.

(Geerbt von Exception)
Message

Ruft eine Nachricht ab, die die aktuelle Ausnahme beschreibt.

(Geerbt von Exception)
Source

Dient zum Abrufen oder Festlegen des Namens der Anwendung oder des Objekts, das den Fehler verursacht.

(Geerbt von Exception)
StackTrace

Ruft eine Zeichenfolgendarstellung der unmittelbaren Frames im Aufrufstapel ab.

(Geerbt von Exception)
TargetSite

Ruft die Methode ab, die die aktuelle Ausnahme auslöst.

(Geerbt von Exception)

Methoden

Name Beschreibung
Equals(Object)

Bestimmt, ob das angegebene Objekt gleich dem aktuellen Objekt ist.

(Geerbt von Object)
GetBaseException()

Wenn sie in einer abgeleiteten Klasse überschrieben wird, wird die Exception Ursache einer oder mehrerer nachfolgenden Ausnahmen zurückgegeben.

(Geerbt von Exception)
GetHashCode()

Dient als Standardhashfunktion.

(Geerbt von Object)
GetObjectData(SerializationInfo, StreamingContext)

Wenn sie in einer abgeleiteten Klasse überschrieben wird, werden die SerializationInfo Informationen zur Ausnahme festgelegt.

(Geerbt von Exception)
GetType()

Ruft den Laufzeittyp der aktuellen Instanz ab.

(Geerbt von Exception)
MemberwiseClone()

Erstellt eine flache Kopie der aktuellen Object.

(Geerbt von Object)
ToString()

Erstellt und gibt eine Zeichenfolgendarstellung der aktuellen Ausnahme zurück.

(Geerbt von Exception)

Ereignisse

Name Beschreibung
SerializeObjectState

Tritt auf, wenn eine Ausnahme serialisiert wird, um ein Ausnahmestatusobjekt zu erstellen, das serialisierte Daten zu der Ausnahme enthält.

(Geerbt von Exception)

Gilt für:

Weitere Informationen