InstallException Klas

Definitie

De uitzondering die optreedt wanneer er een fout optreedt tijdens de doorvoer-, terugdraai- of verwijderingsfase van een installatie.

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

Voorbeelden

Het volgende voorbeeld, plus de voorbeelden in de InstallException constructors, vormen samen een voorbeeld met een assembly met een eigen installatieprogramma. Het installatieprogramma heeft de naam MyInstaller, die een kenmerk RunInstallerAttributeheeft, waarmee wordt aangegeven dat dit installatieprogramma wordt aangeroepen door Installutil.exe (installatieprogramma). Installutil.exe (Installer Tool) roept de methoden Commit, RollbackInstall en Uninstall. De code veronderstelt Commit dat een bestand met de naam FileDoesNotExist.txt bestaat voordat de installatie van de assembly kan worden doorgevoerd. Als het bestand FileDoesNotExist.txt niet bestaat, Commit wordt een InstallException. Hetzelfde geldt voor het geval waarin Uninstall een verwijdering alleen plaatsvindt als er een bestand met de naam FileDoesNotExist.txt bestaat. Anders verheft het een InstallException. In Rollbackwordt een codefragment uitgevoerd, wat een uitzondering kan veroorzaken. Als de uitzondering wordt gegenereerd, wordt deze gepakt en wordt er een InstallException gegenereerd met die uitzondering die aan deze uitzondering wordt doorgegeven.

Note

Voer dit voorbeeld uit met behulp van Installutil.exe. Typ dit in de opdrachtprompt:

Installutil InstallException.exe

– of –

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

Constructors

Name Description
InstallException()

Initialiseert een nieuw exemplaar van de InstallException klasse.

InstallException(SerializationInfo, StreamingContext)

Initialiseert een nieuw exemplaar van de InstallException klasse met geserialiseerde gegevens.

InstallException(String, Exception)

Initialiseert een nieuw exemplaar van de InstallException klasse en geeft het bericht op dat aan de gebruiker moet worden weergegeven en een verwijzing naar de interne uitzondering die de oorzaak van deze uitzondering is.

InstallException(String)

Initialiseert een nieuw exemplaar van de InstallException klasse en geeft het bericht op dat aan de gebruiker moet worden weergegeven.

Eigenschappen

Name Description
Data

Hiermee haalt u een verzameling sleutel-waardeparen op die aanvullende door de gebruiker gedefinieerde informatie over de uitzondering bieden.

(Overgenomen van Exception)
HelpLink

Hiermee haalt u een koppeling op naar het Help-bestand dat aan deze uitzondering is gekoppeld.

(Overgenomen van Exception)
HResult

Hiermee wordt HRESULT opgehaald of ingesteld, een gecodeerde numerieke waarde die is toegewezen aan een specifieke uitzondering.

(Overgenomen van Exception)
InnerException

Hiermee haalt u het Exception exemplaar op dat de huidige uitzondering heeft veroorzaakt.

(Overgenomen van Exception)
Message

Hiermee wordt een bericht weergegeven waarin de huidige uitzondering wordt beschreven.

(Overgenomen van Exception)
Source

Hiermee wordt de naam van de toepassing of het object dat de fout veroorzaakt, opgehaald of ingesteld.

(Overgenomen van Exception)
StackTrace

Hiermee haalt u een tekenreeksweergave van de directe frames op de aanroepstack op.

(Overgenomen van Exception)
TargetSite

Hiermee haalt u de methode op waarmee de huidige uitzondering wordt gegenereerd.

(Overgenomen van Exception)

Methoden

Name Description
Equals(Object)

Bepaalt of het opgegeven object gelijk is aan het huidige object.

(Overgenomen van Object)
GetBaseException()

Wanneer deze wordt overschreven in een afgeleide klasse, retourneert u de Exception hoofdoorzaak van een of meer volgende uitzonderingen.

(Overgenomen van Exception)
GetHashCode()

Fungeert als de standaardhashfunctie.

(Overgenomen van Object)
GetObjectData(SerializationInfo, StreamingContext)

Wanneer deze wordt overschreven in een afgeleide klasse, stelt u de SerializationInfo met informatie over de uitzondering in.

(Overgenomen van Exception)
GetType()

Hiermee haalt u het runtimetype van het huidige exemplaar op.

(Overgenomen van Exception)
MemberwiseClone()

Hiermee maakt u een ondiepe kopie van de huidige Object.

(Overgenomen van Object)
ToString()

Hiermee maakt en retourneert u een tekenreeksweergave van de huidige uitzondering.

(Overgenomen van Exception)

gebeurtenis

Name Description
SerializeObjectState

Treedt op wanneer een uitzondering wordt geserialiseerd om een uitzonderingsstatusobject te maken dat geserialiseerde gegevens over de uitzondering bevat.

(Overgenomen van Exception)

Van toepassing op

Zie ook