InstallException Klass
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Undantaget som utlöses när ett fel inträffar under inchecknings-, återställnings- eller avinstallationsfasen för en installation.
public ref class InstallException : SystemException
[System.Serializable]
public class InstallException : SystemException
[<System.Serializable>]
type InstallException = class
inherit SystemException
Public Class InstallException
Inherits SystemException
- Arv
- Attribut
Exempel
Följande exempel, plus exemplen InstallException i konstruktorerna, utgör tillsammans ett exempel som visar en sammansättning som har ett eget installationsprogram. Installationsprogrammet heter MyInstaller, som har ett attribut RunInstallerAttribute, som anger att installationsprogrammet kommer att anropas av Installutil.exe (installationsverktyg).
Installutil.exe (Installationsverktyg) anropar metoderna Commit, Rollbackoch InstallUninstall. Koden i Commit förutsätter att en fil med namnet FileDoesNotExist.txt finns innan installationen av sammansättningen kan genomföras. Om filen FileDoesNotExist.txt inte finns Commit genererar du en InstallException. Samma sak gäller när en avinstallation endast sker om en fil med Uninstall namnet FileDoesNotExist.txt finns. Annars höjs en InstallException. I Rollbackkörs ett kodfragment, vilket kan generera ett undantag. Om undantaget utlöses fångas det och ett InstallException upphöjs med det undantaget som skickas till det.
Note
Kör det här exemplet med hjälp av Installutil.exe. Skriv detta i kommandotolken:
Installutil InstallException.exe
-eller-
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
Konstruktorer
| Name | Description |
|---|---|
| InstallException() |
Initierar en ny instans av InstallException klassen. |
| InstallException(SerializationInfo, StreamingContext) |
Initierar en ny instans av InstallException klassen med serialiserade data. |
| InstallException(String, Exception) |
Initierar en ny instans av InstallException klassen och anger meddelandet som ska visas för användaren och en referens till det inre undantaget som är orsaken till det här undantaget. |
| InstallException(String) |
Initierar en ny instans av InstallException klassen och anger meddelandet som ska visas för användaren. |
Egenskaper
| Name | Description |
|---|---|
| Data |
Hämtar en samling nyckel/värde-par som ger ytterligare användardefinierad information om undantaget. (Ärvd från Exception) |
| HelpLink |
Hämtar eller anger en länk till hjälpfilen som är associerad med det här undantaget. (Ärvd från Exception) |
| HResult |
Hämtar eller anger HRESULT, ett kodat numeriskt värde som har tilldelats ett specifikt undantag. (Ärvd från Exception) |
| InnerException |
Hämtar den Exception instans som orsakade det aktuella undantaget. (Ärvd från Exception) |
| Message |
Hämtar ett meddelande som beskriver det aktuella undantaget. (Ärvd från Exception) |
| Source |
Hämtar eller anger namnet på programmet eller objektet som orsakar felet. (Ärvd från Exception) |
| StackTrace |
Hämtar en strängrepresentation av de omedelbara ramarna i anropsstacken. (Ärvd från Exception) |
| TargetSite |
Hämtar den metod som utlöser det aktuella undantaget. (Ärvd från Exception) |
Metoder
| Name | Description |
|---|---|
| Equals(Object) |
Avgör om det angivna objektet är lika med det aktuella objektet. (Ärvd från Object) |
| GetBaseException() |
När den åsidosätts i en härledd klass returnerar den Exception som är rotorsaken till ett eller flera efterföljande undantag. (Ärvd från Exception) |
| GetHashCode() |
Fungerar som standard-hash-funktion. (Ärvd från Object) |
| GetObjectData(SerializationInfo, StreamingContext) |
Föråldrad.
När åsidosättas i en härledd klass anger du SerializationInfo med information om undantaget. (Ärvd från Exception) |
| GetType() |
Hämtar körningstypen för den aktuella instansen. (Ärvd från Exception) |
| MemberwiseClone() |
Skapar en ytlig kopia av den aktuella Object. (Ärvd från Object) |
| ToString() |
Skapar och returnerar en strängrepresentation av det aktuella undantaget. (Ärvd från Exception) |
Händelser
| Name | Description |
|---|---|
| SerializeObjectState |
Föråldrad.
Inträffar när ett undantag serialiseras för att skapa ett undantagstillståndsobjekt som innehåller serialiserade data om undantaget. (Ärvd från Exception) |