InstallException Classe

Definição

A exceção que é lançada quando ocorre um erro durante a fase de commit, rollback ou desinstalação de uma instalação.

public ref class InstallException : SystemException
[System.Serializable]
public class InstallException : SystemException
[<System.Serializable>]
type InstallException = class
    inherit SystemException
Public Class InstallException
Inherits SystemException
Herança
InstallException
Atributos

Exemplos

O exemplo seguinte, mais os exemplos nos InstallException construtores, formam juntos um exemplo que mostra um conjunto com o seu próprio instalador. O instalador chama-se MyInstaller, que tem um atributo RunInstallerAttribute, indicando que este instalador será invocado por Installutil.exe (Ferramenta de Instalação). Installutil.exe (Ferramenta de Instalação) chama os métodos Commit, Rollback, Install e Uninstall. O código em Commit pressupõe que existe um ficheiro nomeado FileDoesNotExist.txt antes de a instalação do assembly poder ser confirmada. Se o ficheiro FileDoesNotExist.txt não existir, Commit gera um InstallException. O mesmo acontece quando Uninstall a desinstalação só acontece se existir um ficheiro nomeado FileDoesNotExist.txt . Caso contrário, levanta um InstallException. Em Rollback, é executado um fragmento de código, que pode criar uma exceção. Se a exceção for levantada, é apanhada e an InstallException é levantada, com essa exceção a ser passada para ele.

Note

Executa este exemplo com a ajuda de Installutil.exe. Escreva isto no prompt de comandos:

Installutil InstallException.exe

-ou-

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

Construtores

Name Description
InstallException()

Inicializa uma nova instância da InstallException classe.

InstallException(SerializationInfo, StreamingContext)

Inicializa uma nova instância da InstallException classe com dados serializados.

InstallException(String, Exception)

Inicializa uma nova instância da InstallException classe e especifica a mensagem a mostrar ao utilizador, bem como uma referência à exceção interna que é a causa dessa exceção.

InstallException(String)

Inicializa uma nova instância da InstallException classe e especifica a mensagem a mostrar ao utilizador.

Propriedades

Name Description
Data

Obtém uma coleção de pares chave/valor que fornecem informação adicional definida pelo utilizador sobre a exceção.

(Herdado de Exception)
HelpLink

Obtém ou define um link para o ficheiro de ajuda associado a esta exceção.

(Herdado de Exception)
HResult

Recebe ou define HRESULT, um valor numérico codificado atribuído a uma exceção específica.

(Herdado de Exception)
InnerException

Obtém a Exception instância que causou a exceção atual.

(Herdado de Exception)
Message

Recebe uma mensagem que descreve a exceção atual.

(Herdado de Exception)
Source

Obtém ou define o nome do aplicativo ou o objeto que causa o erro.

(Herdado de Exception)
StackTrace

Obtém uma representação string dos frames imediatos na stack de chamadas.

(Herdado de Exception)
TargetSite

Obtém o método que lança a exceção atual.

(Herdado de Exception)

Métodos

Name Description
Equals(Object)

Determina se o objeto especificado é igual ao objeto atual.

(Herdado de Object)
GetBaseException()

Quando sobrescrito numa classe derivada, devolve o Exception que é a causa raiz de uma ou mais exceções subsequentes.

(Herdado de Exception)
GetHashCode()

Serve como função de hash predefinida.

(Herdado de Object)
GetObjectData(SerializationInfo, StreamingContext)

Quando sobreposto numa classe derivada, define a SerializationInfo informação com sobre a exceção.

(Herdado de Exception)
GetType()

Obtém o tipo de execução da instância atual.

(Herdado de Exception)
MemberwiseClone()

Cria uma cópia superficial do atual Object.

(Herdado de Object)
ToString()

Cria e devolve uma representação string da exceção atual.

(Herdado de Exception)

evento

Name Description
SerializeObjectState

Ocorre quando uma exceção é serializada para criar um objeto de estado de exceção que contém dados serializados sobre a exceção.

(Herdado de Exception)

Aplica-se a

Ver também