通过


CryptographicException 构造函数

定义

初始化 CryptographicException 类的新实例。

重载

名称 说明
CryptographicException()

使用默认属性初始化类的新实例 CryptographicException

CryptographicException(Int32)

使用指定的HRESULT错误代码初始化类的新实例CryptographicException

CryptographicException(String)

使用指定的错误消息初始化类的新实例 CryptographicException

CryptographicException(SerializationInfo, StreamingContext)
已过时.

使用序列化的数据初始化 CryptographicException 类的新实例。

CryptographicException(String, Exception)

使用指定的错误消息和对作为此异常原因的内部异常的引用初始化类的新实例 CryptographicException

CryptographicException(String, String)

用指定格式的指定错误消息初始化类的新实例 CryptographicException

CryptographicException()

Source:
CryptographicException.cs
Source:
CryptographicException.cs
Source:
CryptographicException.cs
Source:
CryptographicException.cs
Source:
CryptographicException.cs

使用默认属性初始化类的新实例 CryptographicException

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

示例

下面的代码示例演示如何构造不带参数的函数 CryptographicException 。 该代码示例是 CryptographicException 类中的一个较大示例的一部分。

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

注解

下表显示了实例 CryptographicException的初始属性值。

财产 价值
InnerException null
Message 本地化的错误消息字符串。

适用于

CryptographicException(Int32)

Source:
CryptographicException.cs
Source:
CryptographicException.cs
Source:
CryptographicException.cs
Source:
CryptographicException.cs
Source:
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错误代码。

示例

下面的代码示例演示如何使用错误代码构造 CryptographicExceptionCryptographicUnexpectedOperationException 该代码示例是 CryptographicException 类中的一个较大示例的一部分。

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

注解

构造函数接受系统错误代码,并将属性设置为与 <a0/a0> 对应的本地化消息。

下表显示了实例 CryptographicException的初始属性值。

财产 价值
InnerException null
Message 本地化的错误消息字符串。

适用于

CryptographicException(String)

Source:
CryptographicException.cs
Source:
CryptographicException.cs
Source:
CryptographicException.cs
Source:
CryptographicException.cs
Source:
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 = ("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)

Source:
CryptographicException.cs
Source:
CryptographicException.cs
Source:
CryptographicException.cs
Source:
CryptographicException.cs
Source:
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);
[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);
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}")>]
new System.Security.Cryptography.CryptographicException : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Security.Cryptography.CryptographicException
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)

Source:
CryptographicException.cs
Source:
CryptographicException.cs
Source:
CryptographicException.cs
Source:
CryptographicException.cs
Source:
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 = ("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 属性返回传入构造函数的相同值,或者 nullInnerException 属性未向构造函数提供内部异常值。

下表显示了实例 CryptographicException的初始属性值。

财产 价值
InnerException 内部异常引用。
Message 错误消息字符串。

另请参阅

适用于

CryptographicException(String, String)

Source:
CryptographicException.cs
Source:
CryptographicException.cs
Source:
CryptographicException.cs
Source:
CryptographicException.cs
Source:
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 = "{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 错误消息字符串。

适用于