CryptographicException 建構函式

定義

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

多載

CryptographicException()

使用預設屬性,初始化 CryptographicException 類別的新執行個體。

CryptographicException(Int32)

使用指定的 HRESULT 錯誤碼,初始化 CryptographicException 類別的新執行個體。

CryptographicException(String)

使用指定的錯誤訊息,初始化 CryptographicException 類別的新執行個體。

CryptographicException(SerializationInfo, StreamingContext)
已淘汰.

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

CryptographicException(String, Exception)

使用指定的錯誤訊息以及造成此例外狀況的內部例外狀況的參考,初始化 CryptographicException 類別的新執行個體。

CryptographicException(String, String)

以指定的格式使用指定的錯誤訊息,初始化 CryptographicException 類別的新執行個體。

CryptographicException()

來源:
CryptographicException.cs
來源:
CryptographicException.cs
來源:
CryptographicException.cs

使用預設屬性,初始化 CryptographicException 類別的新執行個體。

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

範例

下列程式碼範例示範如何建構 CryptographicException 不含參數的 。 此程式碼範例是針對 類別提供的較大範例的 CryptographicException 一部分。

CryptographicException^ cryptographicException = gcnew CryptographicException;
CryptographicException cryptographicException =
    new CryptographicException();
Dim cryptographicException As New CryptographicException

備註

下表顯示 CryptographicException 執行個體的初始屬性值。

屬性
InnerException null.
Message 當地語系化的錯誤訊息字串。

適用於

CryptographicException(Int32)

來源:
CryptographicException.cs
來源:
CryptographicException.cs
來源:
CryptographicException.cs

使用指定的 HRESULT 錯誤碼,初始化 CryptographicException 類別的新執行個體。

public:
 CryptographicException(int hr);
public CryptographicException (int hr);
new System.Security.Cryptography.CryptographicException : int -> System.Security.Cryptography.CryptographicException
Public Sub New (hr As Integer)

參數

hr
Int32

HRESULT 錯誤碼。

範例

下列程式碼範例示範如何使用 的錯誤碼來 CryptographicUnexpectedOperationException 建構 CryptographicException 。 此程式碼範例是針對 類別提供的較大範例的 CryptographicException 一部分。

int exceptionNumber = (int)0x80131431;
CryptographicException^ cryptographicException = gcnew CryptographicException( exceptionNumber );
int exceptionNumber = unchecked((int)0x80131431);
CryptographicException cryptographicException =
    new CryptographicException(exceptionNumber);
Dim exceptionNumber As Integer = &H80131431
Dim cryptographicException As _
    New CryptographicException(exceptionNumber)

備註

CryptographicException 構函式會接受系統 HRESULT 錯誤碼, Message 並將 屬性設定為對應至 的 HRESULT 當地語系化訊息。

下表顯示 CryptographicException 執行個體的初始屬性值。

屬性
InnerException null.
Message 當地語系化的錯誤訊息字串。

適用於

CryptographicException(String)

來源:
CryptographicException.cs
來源:
CryptographicException.cs
來源:
CryptographicException.cs

使用指定的錯誤訊息,初始化 CryptographicException 類別的新執行個體。

public:
 CryptographicException(System::String ^ message);
public CryptographicException (string? message);
public CryptographicException (string message);
new System.Security.Cryptography.CryptographicException : string -> System.Security.Cryptography.CryptographicException
Public Sub New (message As String)

參數

message
String

解釋例外狀況原因的錯誤訊息。

範例

下列程式碼範例示範如何使用自訂錯誤訊息建構 CryptographicException 。 此程式碼範例是針對 類別提供的較大範例的 CryptographicException 一部分。

String^ errorMessage = (L"Unexpected Operation exception.");
CryptographicException^ cryptographicException = gcnew CryptographicException( errorMessage );
string errorMessage = ("Unexpected Operation exception.");
CryptographicException cryptographicException =
    new CryptographicException(errorMessage);
Dim errorMessage As String = "Unexpected Operation exception."
Dim cryptographicException As New CryptographicException(errorMessage)

備註

下表顯示 CryptographicException 執行個體的初始屬性值。

屬性
InnerException null.
Message 錯誤訊息字串。

適用於

CryptographicException(SerializationInfo, StreamingContext)

來源:
CryptographicException.cs
來源:
CryptographicException.cs
來源:
CryptographicException.cs

警告

This API supports obsolete formatter-based serialization. It should not be called or extended by application code.

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

protected:
 CryptographicException(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);
protected CryptographicException (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
[System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
protected CryptographicException (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
new System.Security.Cryptography.CryptographicException : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Security.Cryptography.CryptographicException
[<System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
new System.Security.Cryptography.CryptographicException : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Security.Cryptography.CryptographicException
Protected Sub New (info As SerializationInfo, context As StreamingContext)

參數

info
SerializationInfo

存放序列物件資料的物件。

context
StreamingContext

關於來源或目的端的內容資訊。

屬性

備註

這個建構函式是在還原序列化期間呼叫,以便重新組成透過資料流傳輸的例外狀況物件。

適用於

CryptographicException(String, Exception)

來源:
CryptographicException.cs
來源:
CryptographicException.cs
來源:
CryptographicException.cs

使用指定的錯誤訊息以及造成此例外狀況的內部例外狀況的參考,初始化 CryptographicException 類別的新執行個體。

public:
 CryptographicException(System::String ^ message, Exception ^ inner);
public CryptographicException (string? message, Exception? inner);
public CryptographicException (string message, Exception inner);
new System.Security.Cryptography.CryptographicException : string * Exception -> System.Security.Cryptography.CryptographicException
Public Sub New (message As String, inner As Exception)

參數

message
String

解釋例外狀況原因的錯誤訊息。

inner
Exception

做為目前例外狀況發生原因的例外狀況。 如果 inner 參數不是 null,則目前的例外狀況會在處理內部例外的 catch 區塊中引發。

範例

下列程式碼範例示範如何使用自訂錯誤訊息和內部例外狀況來建構 CryptographicException 。 此程式碼範例是針對 類別提供的較大範例的 CryptographicException 一部分。

String^ errorMessage = (L"The current operation is not supported.");
NullReferenceException^ nullException = gcnew NullReferenceException;
CryptographicException^ cryptographicException = gcnew CryptographicException( errorMessage,nullException );
string errorMessage = ("The current operation is not supported.");
NullReferenceException nullException = new NullReferenceException();
CryptographicException cryptographicException = 
    new CryptographicException(errorMessage, nullException);
Dim errorMessage As String = "The current operation is not supported."
Dim nullException As New NullReferenceException
Dim cryptographicException As _
    New CryptographicException(errorMessage, nullException)

備註

被擲回以做為前一個例外狀況直接結果的例外狀況,應該在 InnerException 屬性中包含對前一個例外狀況的參考。 InnerException 屬性傳回的值會與傳入建構函式的值相同,或傳回 null (如果 InnerException 屬性未提供內部例外狀況值給建構函式)。

下表顯示 CryptographicException 執行個體的初始屬性值。

屬性
InnerException 內部例外狀況參考。
Message 錯誤訊息字串。

另請參閱

適用於

CryptographicException(String, String)

來源:
CryptographicException.cs
來源:
CryptographicException.cs
來源:
CryptographicException.cs

以指定的格式使用指定的錯誤訊息,初始化 CryptographicException 類別的新執行個體。

public:
 CryptographicException(System::String ^ format, System::String ^ insert);
public CryptographicException (string format, string? insert);
public CryptographicException (string format, string insert);
new System.Security.Cryptography.CryptographicException : string * string -> System.Security.Cryptography.CryptographicException
Public Sub New (format As String, insert As String)

參數

format
String

用來輸出錯誤訊息的格式。

insert
String

解釋例外狀況原因的錯誤訊息。

範例

下列程式碼範例示範如何使用時間格式和目前日期來建構 CryptographicException 。 此程式碼範例是針對 類別提供的較大範例的 CryptographicException 一部分。

String^ dateFormat = L"{0:t}";
String^ timeStamp = (DateTime::Now.ToString());
CryptographicException^ cryptographicException = gcnew CryptographicException( dateFormat,timeStamp );
string dateFormat = "{0:t}";
string timeStamp = (DateTime.Now.ToString());
CryptographicException cryptographicException = 
    new CryptographicException(dateFormat, timeStamp);
Dim dateFormat As String = "{0:t}"
Dim timeStamp As String = DateTime.Now.ToString()
Dim cryptographicException As _
    New CryptographicException(dateFormat, timeStamp)

備註

下表顯示 CryptographicException 執行個體的初始屬性值。

屬性
InnerException null.
Message 錯誤訊息字串。

適用於