InstallException Clase
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Excepción que se produce cuando se produce un error durante la fase de confirmación, reversión o desinstalación de una instalación.
public ref class InstallException : SystemException
[System.Serializable]
public class InstallException : SystemException
[<System.Serializable>]
type InstallException = class
inherit SystemException
Public Class InstallException
Inherits SystemException
- Herencia
- Atributos
Ejemplos
En el ejemplo siguiente, además de los ejemplos de los InstallException constructores, se crea un ejemplo que muestra un ensamblado que tiene su propio instalador. El instalador se denomina MyInstaller, que tiene un atributo RunInstallerAttribute, que indica que Installutil.exe (Herramienta instalador) invocará este instalador.
Installutil.exe (Herramienta instalador) llama a los métodos Commit, RollbackInstall y Uninstall. El código de Commit supone que existe un archivo denominado FileDoesNotExist.txt antes de que se pueda confirmar la instalación del ensamblado. Si el archivo FileDoesNotExist.txt no existe, Commit genera un InstallException. Lo mismo sucede con Uninstall en el que solo se producirá una desinstalación si existe un archivo denominado FileDoesNotExist.txt . De lo contrario, genera un InstallException. En Rollback, se ejecuta un fragmento de código, que podría generar una excepción. Si se genera la excepción, se detecta y InstallException se genera una excepción con esa excepción que se le pasa.
Note
Ejecute este ejemplo con la ayuda de Installutil.exe. Escriba esto en el símbolo del sistema:
Installutil InstallException.exe
O bien
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
Constructores
| Nombre | Description |
|---|---|
| InstallException() |
Inicializa una nueva instancia de la clase InstallException. |
| InstallException(SerializationInfo, StreamingContext) |
Inicializa una nueva instancia de la InstallException clase con datos serializados. |
| InstallException(String, Exception) |
Inicializa una nueva instancia de la InstallException clase y especifica el mensaje que se va a mostrar al usuario y una referencia a la excepción interna que es la causa de esta excepción. |
| InstallException(String) |
Inicializa una nueva instancia de la InstallException clase y especifica el mensaje que se va a mostrar al usuario. |
Propiedades
| Nombre | Description |
|---|---|
| Data |
Obtiene una colección de pares clave-valor que proporcionan información adicional definida por el usuario sobre la excepción. (Heredado de Exception) |
| HelpLink |
Obtiene o establece un vínculo al archivo de ayuda asociado a esta excepción. (Heredado de Exception) |
| HResult |
Obtiene o establece HRESULT, un valor numérico codificado que se asigna a una excepción específica. (Heredado de Exception) |
| InnerException |
Obtiene la Exception instancia que provocó la excepción actual. (Heredado de Exception) |
| Message |
Obtiene un mensaje que describe la excepción actual. (Heredado de Exception) |
| Source |
Obtiene o establece el nombre de la aplicación o el objeto que provoca el error. (Heredado de Exception) |
| StackTrace |
Obtiene una representación de cadena de los fotogramas inmediatos en la pila de llamadas. (Heredado de Exception) |
| TargetSite |
Obtiene el método que produce la excepción actual. (Heredado de Exception) |
Métodos
| Nombre | Description |
|---|---|
| Equals(Object) |
Determina si el objeto especificado es igual al objeto actual. (Heredado de Object) |
| GetBaseException() |
Cuando se reemplaza en una clase derivada, devuelve la Exception causa principal de una o varias excepciones posteriores. (Heredado de Exception) |
| GetHashCode() |
Actúa como la función hash predeterminada. (Heredado de Object) |
| GetObjectData(SerializationInfo, StreamingContext) |
Cuando se reemplaza en una clase derivada, establece con SerializationInfo información sobre la excepción. (Heredado de Exception) |
| GetType() |
Obtiene el tipo de tiempo de ejecución de la instancia actual. (Heredado de Exception) |
| MemberwiseClone() |
Crea una copia superficial del Objectactual. (Heredado de Object) |
| ToString() |
Crea y devuelve una representación de cadena de la excepción actual. (Heredado de Exception) |
Eventos
| Nombre | Description |
|---|---|
| SerializeObjectState |
Se produce cuando se serializa una excepción para crear un objeto de estado de excepción que contiene datos serializados sobre la excepción. (Heredado de Exception) |