InstallException 類別

定義

安裝的認可、復原或解除安裝階段發生錯誤時所擲回的例外狀況。

public ref class InstallException : SystemException
[System.Serializable]
public class InstallException : SystemException
[<System.Serializable>]
type InstallException = class
    inherit SystemException
Public Class InstallException
Inherits SystemException
繼承
InstallException
屬性

範例

下列範例加上建構函式中的 InstallException 範例,組成一個範例,其中顯示具有自己的安裝程式的元件。 安裝程式名為 MyInstaller,其具有 屬性 RunInstallerAttribute,表示安裝程式將會由 Installutil.exe (Installer Tool) 叫用此安裝程式。 Installutil.exe (安裝程式工具) 呼叫、 RollbackInstallUninstall方法Commit。 中的 Commit 程式代碼假設名為 FileDoesNotExist.txt 的檔案存在,才能認可元件的安裝。 如果檔案 FileDoesNotExist.txt 不存在, Commit 則引發 InstallException。 同樣地, Uninstall 只有在名為 FileDoesNotExist.txt 的檔案存在時,才會發生卸載的情況。 否則會 InstallException引發 。 在中 Rollback,會執行代碼段,這可能會引發例外狀況。 如果引發例外狀況,就會攔截該例外狀況,並引發 ,並將 InstallException 該例外狀況傳遞給該例外狀況。

注意

使用 Installutil.exe 的說明執行此範例。 在命令提示字元中輸入此值:

Installutil InstallException.exe

-或-

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

建構函式

InstallException()

初始化 InstallException 類別的新執行個體。

InstallException(SerializationInfo, StreamingContext)

使用序列化資料,初始化 InstallException 類別的新執行個體。

InstallException(String)

初始化 InstallException 類別的新執行個體,並且指定對使用者顯示的訊息。

InstallException(String, Exception)

初始化 InstallException 類別的新執行個體,指定對使用者顯示的訊息以及造成這個例外狀況的內部例外狀況參考。

屬性

Data

取得鍵值組的集合,這些鍵值組會提供關於例外狀況的其他使用者定義資訊。

(繼承來源 Exception)
HelpLink

取得或設定與這個例外狀況相關聯的說明檔連結。

(繼承來源 Exception)
HResult

取得或設定 HRESULT,它是指派給特定例外狀況的編碼數值。

(繼承來源 Exception)
InnerException

取得造成目前例外狀況的 Exception 執行個體。

(繼承來源 Exception)
Message

取得描述目前例外狀況的訊息。

(繼承來源 Exception)
Source

取得或設定造成錯誤的應用程式或物件的名稱。

(繼承來源 Exception)
StackTrace

取得呼叫堆疊上即時運算框架的字串表示。

(繼承來源 Exception)
TargetSite

取得擲回目前例外狀況的方法。

(繼承來源 Exception)

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetBaseException()

在衍生類別中覆寫時,傳回一或多個後續的例外狀況的根本原因 Exception

(繼承來源 Exception)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetObjectData(SerializationInfo, StreamingContext)
已淘汰.

在衍生類別中覆寫時,使用例外狀況的資訊設定 SerializationInfo

(繼承來源 Exception)
GetType()

取得目前執行個體的執行階段類型。

(繼承來源 Exception)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

建立並傳回目前例外狀況的字串表示。

(繼承來源 Exception)

事件

SerializeObjectState
已淘汰.

當例外狀況序列化,以建立包含例外狀況相關序列化資料的例外狀況狀態物件時,就會發生此事件。

(繼承來源 Exception)

適用於

另請參閱