InstallException クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
インストールのコミット、ロールバック、またはアンインストールフェーズ中にエラーが発生したときにスローされる例外。
public ref class InstallException : SystemException
[System.Serializable]
public class InstallException : SystemException
[<System.Serializable>]
type InstallException = class
inherit SystemException
Public Class InstallException
Inherits SystemException
- 継承
- 属性
例
次の例に加えて、 InstallException コンストラクターの例を組み合わせて、独自のインストーラーを持つアセンブリを示す例を構成します。 インストーラーには MyInstaller という名前が付けられ、属性 RunInstallerAttributeがあり、このインストーラーが Installutil.exe (インストーラー ツール) によって呼び出されることを示します。
Installutil.exe (インストーラー ツール) は、 Commit、 Rollback、 Install 、および Uninstallメソッドを呼び出します。
Commitのコードは、アセンブリのインストールをコミットする前に、FileDoesNotExist.txtという名前のファイルが存在することを前提とします。 ファイル FileDoesNotExist.txt が存在しない場合、 Commit は InstallExceptionを発生させます。
FileDoesNotExist.txtという名前のファイルが存在する場合にのみアンインストールが行われるUninstallの場合も同じです。 それ以外の場合は、 InstallExceptionが発生します。
Rollbackでは、コード フラグメントが実行され、例外が発生する可能性があります。 例外が発生すると、例外がキャッチされ、その例外が渡された状態で InstallException が発生します。
Note
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, Exception) |
InstallException クラスの新しいインスタンスを初期化し、ユーザーに表示するメッセージと、この例外の原因である内部例外への参照を指定します。 |
| InstallException(String) |
InstallException クラスの新しいインスタンスを初期化し、ユーザーに表示するメッセージを指定します。 |
プロパティ
| 名前 | 説明 |
|---|---|
| Data |
例外に関する追加のユーザー定義情報を提供するキーと値のペアのコレクションを取得します。 (継承元 Exception) |
| HelpLink |
この例外に関連付けられているヘルプ ファイルへのリンクを取得または設定します。 (継承元 Exception) |
| HResult |
特定の例外に割り当てられるコード化された数値である HRESULT を取得または設定します。 (継承元 Exception) |
| InnerException |
現在の例外の原因となった Exception インスタンスを取得します。 (継承元 Exception) |
| Message |
現在の例外を説明するメッセージを取得します。 (継承元 Exception) |
| Source |
エラーの原因となるアプリケーションまたはオブジェクトの名前を取得または設定します。 (継承元 Exception) |
| StackTrace |
呼び出し履歴のイミディエイト フレームの文字列表現を取得します。 (継承元 Exception) |
| TargetSite |
現在の例外をスローするメソッドを取得します。 (継承元 Exception) |
メソッド
| 名前 | 説明 |
|---|---|
| Equals(Object) |
指定したオブジェクトが現在のオブジェクトと等しいかどうかを判断します。 (継承元 Object) |
| GetBaseException() |
派生クラスでオーバーライドされた場合、1 つ以上の後続の例外の根本原因である Exception を返します。 (継承元 Exception) |
| GetHashCode() |
既定のハッシュ関数として機能します。 (継承元 Object) |
| GetObjectData(SerializationInfo, StreamingContext) |
派生クラスでオーバーライドされた場合は、例外に関する情報を使用して SerializationInfo を設定します。 (継承元 Exception) |
| GetType() |
現在のインスタンスのランタイム型を取得します。 (継承元 Exception) |
| MemberwiseClone() |
現在の Objectの簡易コピーを作成します。 (継承元 Object) |
| ToString() |
現在の例外の文字列形式を作成して返します。 (継承元 Exception) |
イベント
| 名前 | 説明 |
|---|---|
| SerializeObjectState |
例外に関するシリアル化されたデータを含む例外状態オブジェクトを作成するために例外がシリアル化されるときに発生します。 (継承元 Exception) |