InstallException Classe

Definição

A exceção que é gerada quando ocorre um erro durante a fase de confirmação, reversão ou desinstalação de uma instalação.The exception that is thrown when an error occurs during the commit, rollback, or uninstall phase of an installation.

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

Exemplos

O exemplo a seguir, além dos exemplos nos InstallException construtores, formam um exemplo que mostra um assembly com seu próprio instalador.The following example, plus the examples in the InstallException constructors, together make up an example showing an assembly having its own installer. O instalador é chamado MyInstaller, que tem um atributo RunInstallerAttribute, indicando que este instalador será invocado pelo InstallUtil. exe (ferramenta de instalação).The installer is named MyInstaller, which has an attribute RunInstallerAttribute, indicating that this installer will be invoked by Installutil.exe (Installer Tool). InstallUtil. exe (ferramenta de instalação) chama os métodos Commit, Rollback Install e Uninstall.Installutil.exe (Installer Tool) calls the methods Commit, Rollback, Install and Uninstall. O código em Commit presume que um arquivo chamado FileDoesNotExist.txt exista antes que a instalação do assembly possa ser confirmada.The code in Commit presumes that a file named FileDoesNotExist.txt exists before the installation of the assembly can be committed. Se o arquivo FileDoesNotExist.txt não existir, Commit o gerará InstallExceptionum.If the file FileDoesNotExist.txt does not exist, Commit raises an InstallException. O mesmo é o caso Uninstall no qual uma desinstalação só ocorrerá se um arquivo chamado FileDoesNotExist.txt existir.The same is the case with Uninstall in which an uninstallation will only happen if a file named FileDoesNotExist.txt exists. Caso contrário, ele InstallExceptiongera um.Otherwise it raises an InstallException. No Rollback, um fragmento de código é executado, o que pode gerar uma exceção.In Rollback, a code fragment is executed, which might raise an exception. Se a exceção for gerada, ela será capturada e InstallException um será gerado com essa exceção que está sendo passada para ela.If the exception is raised, it is caught and an InstallException is raised with that exception being passed to it.

Observação

Execute este exemplo com a ajuda de InstallUtil. exe.Run this example with the help of Installutil.exe. Digite isso no prompt de comando:Type this in the command prompt:

Installutil InstallException.exe

- ou --or-

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

InstallException()

Inicializa uma nova instância da classe InstallException.Initializes a new instance of the InstallException class.

InstallException(SerializationInfo, StreamingContext)

Inicializa uma nova instância da classe InstallException com dados serializados.Initializes a new instance of the InstallException class with serialized data.

InstallException(String)

Inicializa uma nova instância da classe InstallException e especifica a mensagem a ser exibida ao usuário.Initializes a new instance of the InstallException class, and specifies the message to display to the user.

InstallException(String, Exception)

Inicializa uma nova instância da classe InstallException e especifica a mensagem a ser exibida ao usuário e uma referência à exceção interna que é a causa dessa exceção.Initializes a new instance of the InstallException class, and specifies the message to display to the user, and a reference to the inner exception that is the cause of this exception.

Propriedades

Data

Obtém uma coleção de pares de chave/valor que fornecem informações adicionais definidas pelo usuário sobre a exceção.Gets a collection of key/value pairs that provide additional user-defined information about the exception.

(Herdado de Exception)
HelpLink

Obtém ou define um link para o arquivo de ajuda associado a essa exceção.Gets or sets a link to the help file associated with this exception.

(Herdado de Exception)
HResult

Obtém ou define HRESULT, um valor numérico codificado que é atribuído a uma exceção específica.Gets or sets HRESULT, a coded numerical value that is assigned to a specific exception.

(Herdado de Exception)
InnerException

Obtém a instância Exception que causou a exceção atual.Gets the Exception instance that caused the current exception.

(Herdado de Exception)
Message

Obtém uma mensagem que descreve a exceção atual.Gets a message that describes the current exception.

(Herdado de Exception)
Source

Obtém ou define o nome do aplicativo ou objeto que causa o erro.Gets or sets the name of the application or the object that causes the error.

(Herdado de Exception)
StackTrace

Obtém uma representação de cadeia de caracteres de quadros imediatos na pilha de chamadas.Gets a string representation of the immediate frames on the call stack.

(Herdado de Exception)
TargetSite

Obtém o método que gerou a exceção atual.Gets the method that throws the current exception.

(Herdado de Exception)

Métodos

Equals(Object)

Determina se o objeto especificado é igual ao objeto atual.Determines whether the specified object is equal to the current object.

(Herdado de Object)
GetBaseException()

Quando substituído em uma classe derivada, retorna a Exception que é a causa raiz de uma ou mais exceções subsequentes.When overridden in a derived class, returns the Exception that is the root cause of one or more subsequent exceptions.

(Herdado de Exception)
GetHashCode()

Serve como a função de hash padrão.Serves as the default hash function.

(Herdado de Object)
GetObjectData(SerializationInfo, StreamingContext)

Quando substituído em uma classe derivada, define o SerializationInfo com informações sobre a exceção.When overridden in a derived class, sets the SerializationInfo with information about the exception.

(Herdado de Exception)
GetType()

Obtém o tipo de tempo de execução da instância atual.Gets the runtime type of the current instance.

(Herdado de Exception)
MemberwiseClone()

Cria uma cópia superficial do Object atual.Creates a shallow copy of the current Object.

(Herdado de Object)
ToString()

Cria e retorna uma representação de cadeia de caracteres da exceção atual.Creates and returns a string representation of the current exception.

(Herdado de Exception)

Eventos

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.Occurs when an exception is serialized to create an exception state object that contains serialized data about the exception.

(Herdado de Exception)

Aplica-se a

Veja também