InstallException Kelas

Definisi

Pengecualian yang dilemparkan ketika kesalahan terjadi selama fase penerapan, pembatalan, atau penghapusan instalasi.

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

Contoh

Contoh berikut, ditambah contoh dalam InstallException konstruktor, bersama-sama membentuk contoh yang menunjukkan perakitan yang memiliki alat penginstalnya sendiri. Alat penginstal diberi nama MyInstaller, yang memiliki atribut RunInstallerAttribute, yang menunjukkan bahwa alat penginstal ini akan dipanggil oleh Installutil.exe (Alat Penginstal). Installutil.exe (Alat PenginstalCommit) memanggil metode , , RollbackInstall dan Uninstall. Kode dalam Commit anggapan bahwa file bernama FileDoesNotExist.txt ada sebelum penginstalan assembly dapat dilakukan. Jika file FileDoesNotExist.txt tidak ada, Commit menaikkan InstallException. Hal yang sama adalah kasus Uninstall di mana penghapusan instalasi hanya akan terjadi jika file bernama FileDoesNotExist.txt ada. Jika tidak, ia akan menaikkan InstallException. Dalam Rollback, fragmen kode dijalankan, yang mungkin menimbulkan pengecualian. Jika pengecualian dinaikkan, pengecualian akan tertangkap dan InstallException dinaikkan dengan pengecualian yang diteruskan ke dalamnya.

Catatan

Jalankan contoh ini dengan bantuan Installutil.exe. Ketik ini di prompt perintah:

Installutil InstallException.exe

-atau-

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

Konstruktor

InstallException()

Menginisialisasi instans baru kelas InstallException.

InstallException(SerializationInfo, StreamingContext)

Menginisialisasi instans InstallException baru kelas dengan data berseri.

InstallException(String)

Menginisialisasi instans InstallException baru kelas, dan menentukan pesan yang akan ditampilkan kepada pengguna.

InstallException(String, Exception)

Menginisialisasi instans InstallException baru kelas, dan menentukan pesan untuk ditampilkan kepada pengguna, dan referensi ke pengecualian dalam yang merupakan penyebab pengecualian ini.

Properti

Data

Mendapatkan kumpulan pasangan kunci/nilai yang memberikan informasi tambahan yang ditentukan pengguna tentang pengecualian.

(Diperoleh dari Exception)
HelpLink

Mendapatkan atau mengatur tautan ke file bantuan yang terkait dengan pengecualian ini.

(Diperoleh dari Exception)
HResult

Mendapatkan atau menetapkan HRESULT, nilai numerik berkode yang ditetapkan ke pengecualian tertentu.

(Diperoleh dari Exception)
InnerException

Mendapatkan instans Exception yang menyebabkan pengecualian saat ini.

(Diperoleh dari Exception)
Message

Mendapatkan pesan yang menjelaskan pengecualian saat ini.

(Diperoleh dari Exception)
Source

Get dan set nama aplikasi atau objek yang menyebabkan kesalahan.

(Diperoleh dari Exception)
StackTrace

Mendapatkan representasi string dari bingkai langsung pada tumpukan panggilan.

(Diperoleh dari Exception)
TargetSite

Mendapatkan metode yang melemparkan pengecualian saat ini.

(Diperoleh dari Exception)

Metode

Equals(Object)

Menentukan apakah objek yang ditentukan sama dengan objek saat ini.

(Diperoleh dari Object)
GetBaseException()

Ketika ditimpa di kelas turunan, mengembalikan Exception yang merupakan akar penyebab dari satu atau beberapa pengecualian berikutnya.

(Diperoleh dari Exception)
GetHashCode()

Berfungsi sebagai fungsi hash default.

(Diperoleh dari Object)
GetObjectData(SerializationInfo, StreamingContext)
Kedaluwarsa.

Saat ditimpa di kelas turunan, mengatur SerializationInfo dengan informasi tentang pengecualian.

(Diperoleh dari Exception)
GetType()

Mendapatkan jenis runtime instans saat ini.

(Diperoleh dari Exception)
MemberwiseClone()

Membuat salinan dangkal dari yang saat ini Object.

(Diperoleh dari Object)
ToString()

Membuat dan mengembalikan representasi string dari pengecualian saat ini.

(Diperoleh dari Exception)

Acara

SerializeObjectState
Kedaluwarsa.

Terjadi ketika pengecualian diserialisasikan untuk membuat objek status pengecualian yang berisi data berseri tentang pengecualian.

(Diperoleh dari Exception)

Berlaku untuk

Lihat juga