TargetException 建構函式

定義

初始化 TargetException 類別的新執行個體。Initializes a new instance of the TargetException class.

多載

TargetException()

使用空的訊息和例外狀況的根本原因,初始化 TargetException 類別的新執行個體。Initializes a new instance of the TargetException class with an empty message and the root cause of the exception.

TargetException(String)

使用指定的訊息和例外狀況的根本原因,初始化 TargetException 類別的新執行個體。Initializes a new instance of the TargetException class with the given message and the root cause exception.

TargetException(SerializationInfo, StreamingContext)

使用指定的序列化 (Serialization) 和內容資訊,初始化 TargetException 類別的新執行個體。Initializes a new instance of the TargetException class with the specified serialization and context information.

TargetException(String, Exception)

使用指定的錯誤訊息以及造成此例外狀況的內部例外狀況的參考,初始化 TargetException 類別的新執行個體。Initializes a new instance of the TargetException class with a specified error message and a reference to the inner exception that is the cause of this exception.

TargetException()

使用空的訊息和例外狀況的根本原因,初始化 TargetException 類別的新執行個體。Initializes a new instance of the TargetException class with an empty message and the root cause of the exception.

public:
 TargetException();
public TargetException ();
Public Sub New ()

備註

InnerException 屬性設為 null,而 HRESULT 錯誤碼設定為 COR_E_TARGET。The InnerException property is set to null and the HRESULT error code is set to COR_E_TARGET.

TargetException 繼承自 ExceptionTargetException inherits from the Exception. 此函式會設定 Exception 物件的屬性,如下表所示。This constructor sets the properties of the Exception object as shown in the following table.

屬性Property Value
InnerException null
Message 空字串("")。The empty string ("").

TargetException(String)

使用指定的訊息和例外狀況的根本原因,初始化 TargetException 類別的新執行個體。Initializes a new instance of the TargetException class with the given message and the root cause exception.

public:
 TargetException(System::String ^ message);
public TargetException (string message);
new System.Reflection.TargetException : string -> System.Reflection.TargetException
Public Sub New (message As String)

參數

message
String

String,描述發生例外狀況的原因。A String describing the reason why the exception occurred.

備註

TargetException 繼承自 ExceptionTargetException inherits from the Exception. 此函式會設定 Exception 物件的屬性,如下表所示。This constructor sets the properties of the Exception object as shown in the following table.

屬性Property Value
InnerException null
Message 訊息字串。The message string.

TargetException(SerializationInfo, StreamingContext)

使用指定的序列化 (Serialization) 和內容資訊,初始化 TargetException 類別的新執行個體。Initializes a new instance of the TargetException class with the specified serialization and context information.

protected:
 TargetException(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);
protected TargetException (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
new System.Reflection.TargetException : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Reflection.TargetException
Protected Sub New (info As SerializationInfo, context As StreamingContext)

參數

info
SerializationInfo

用於序列化或還原序列化物件的資料。The data for serializing or deserializing the object.

context
StreamingContext

物件的目的端和資源。The source of and destination for the object.

TargetException(String, Exception)

使用指定的錯誤訊息以及造成此例外狀況的內部例外狀況的參考,初始化 TargetException 類別的新執行個體。Initializes a new instance of the TargetException class with a specified error message and a reference to the inner exception that is the cause of this exception.

public:
 TargetException(System::String ^ message, Exception ^ inner);
public TargetException (string message, Exception inner);
new System.Reflection.TargetException : string * Exception -> System.Reflection.TargetException
Public Sub New (message As String, inner As Exception)

參數

message
String

解釋例外狀況原因的錯誤訊息。The error message that explains the reason for the exception.

inner
Exception

造成目前例外狀況的例外狀況。The exception that is the cause of the current exception. 如果 inner 參數不是 null,則目前的例外狀況會在處理內部例外的 catch 區塊中引發。If the inner parameter is not null, the current exception is raised in a catch block that handles the inner exception.

備註

被擲回以做為前一個例外狀況直接結果的例外狀況,應該在 InnerException 屬性中包含對前一個例外狀況的參考。An exception that is thrown as a direct result of a previous exception should include a reference to the previous exception in the InnerException property. InnerException 屬性會傳回與傳入建構函式中相同的值;如果 null 屬性沒有提供內部例外值給建構函式,則傳回 InnerExceptionThe InnerException property returns the same value that is passed into the constructor, or null if the InnerException property does not supply the inner exception value to the constructor.

下表顯示 TargetException 執行個體的初始屬性值。The following table shows the initial property values for an instance of TargetException.

屬性Property Value
InnerException 內部例外狀況參考。The inner exception reference.
Message 錯誤訊息字串。The error message string.

另請參閱

適用於