InvalidTimeZoneException 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
初始化 InvalidTimeZoneException 类的新实例。
重载
| InvalidTimeZoneException() |
使用由系统提供的消息初始化 InvalidTimeZoneException 类的新实例。 |
| InvalidTimeZoneException(String) |
使用指定的消息字符串初始化 InvalidTimeZoneException 类的新实例。 |
| InvalidTimeZoneException(SerializationInfo, StreamingContext) |
已过时.
用序列化数据初始化 InvalidTimeZoneException 类的新实例。 |
| InvalidTimeZoneException(String, Exception) |
使用指定的错误消息和对作为此异常原因的内部异常的引用来初始化 InvalidTimeZoneException 类的新实例。 |
InvalidTimeZoneException()
- Source:
- InvalidTimeZoneException.cs
- Source:
- InvalidTimeZoneException.cs
- Source:
- InvalidTimeZoneException.cs
使用由系统提供的消息初始化 InvalidTimeZoneException 类的新实例。
public:
InvalidTimeZoneException();
public InvalidTimeZoneException ();
Public Sub New ()
注解
这是 类的 InvalidTimeZoneException 无参数构造函数。 它将新实例的 属性初始化 Message 为描述错误的系统提供的消息,例如“引发'System.InvalidTimeZoneException'类型的异常”。此消息针对当前系统区域性进行了本地化。
适用于
InvalidTimeZoneException(String)
- Source:
- InvalidTimeZoneException.cs
- Source:
- InvalidTimeZoneException.cs
- Source:
- InvalidTimeZoneException.cs
使用指定的消息字符串初始化 InvalidTimeZoneException 类的新实例。
public:
InvalidTimeZoneException(System::String ^ message);
public InvalidTimeZoneException (string message);
public InvalidTimeZoneException (string? message);
new InvalidTimeZoneException : string -> InvalidTimeZoneException
Public Sub New (message As String)
参数
- message
- String
描述异常的字符串。
注解
作为 message 参数提供的字符串将 Message 分配给 属性。 它应针对当前区域性进行本地化。
适用于
InvalidTimeZoneException(SerializationInfo, StreamingContext)
- Source:
- InvalidTimeZoneException.cs
- Source:
- InvalidTimeZoneException.cs
- Source:
- InvalidTimeZoneException.cs
注意
This API supports obsolete formatter-based serialization. It should not be called or extended by application code.
用序列化数据初始化 InvalidTimeZoneException 类的新实例。
protected:
InvalidTimeZoneException(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);
protected InvalidTimeZoneException (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 InvalidTimeZoneException (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
new InvalidTimeZoneException : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> InvalidTimeZoneException
[<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 InvalidTimeZoneException : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> InvalidTimeZoneException
Protected Sub New (info As SerializationInfo, context As StreamingContext)
参数
- info
- SerializationInfo
包含序列化数据的对象。
- context
- StreamingContext
包含序列化数据的流。
- 属性
例外
注解
代码不直接调用此构造函数来实例化 InvalidTimeZoneException 对象。 相反,当从流反序列化InvalidTimeZoneException对象Deserialize时,它由 IFormatter 对象的 方法调用。
适用于
InvalidTimeZoneException(String, Exception)
- Source:
- InvalidTimeZoneException.cs
- Source:
- InvalidTimeZoneException.cs
- Source:
- InvalidTimeZoneException.cs
使用指定的错误消息和对作为此异常原因的内部异常的引用来初始化 InvalidTimeZoneException 类的新实例。
public:
InvalidTimeZoneException(System::String ^ message, Exception ^ innerException);
public InvalidTimeZoneException (string message, Exception innerException);
public InvalidTimeZoneException (string? message, Exception? innerException);
new InvalidTimeZoneException : string * Exception -> InvalidTimeZoneException
Public Sub New (message As String, innerException As Exception)
参数
- message
- String
描述异常的字符串。
- innerException
- Exception
导致当前异常的异常。
示例
以下代码尝试检索表示 TimeZoneInfo 中央标准时区的 对象。 如果在方法调用中RetrieveTimeZone发生 ,InvalidTimeZoneException则异常处理程序会将异常包装到新InvalidTimeZoneException对象中,该对象将返回给调用方。 然后,调用方异常处理程序会显示有关外部异常和内部异常的信息。
private void HandleInnerException()
{
string timeZoneName = "Any Standard Time";
TimeZoneInfo tz;
try
{
tz = RetrieveTimeZone(timeZoneName);
Console.WriteLine("The time zone display name is {0}.", tz.DisplayName);
}
catch (TimeZoneNotFoundException e)
{
Console.WriteLine("{0} thrown by application", e.GetType().Name);
Console.WriteLine(" Message: {0}", e.Message);
if (e.InnerException != null)
{
Console.WriteLine(" Inner Exception Information:");
Exception innerEx = e.InnerException;
while (innerEx != null)
{
Console.WriteLine(" {0}: {1}", innerEx.GetType().Name, innerEx.Message);
innerEx = innerEx.InnerException;
}
}
}
}
private TimeZoneInfo RetrieveTimeZone(string tzName)
{
try
{
return TimeZoneInfo.FindSystemTimeZoneById(tzName);
}
catch (TimeZoneNotFoundException ex1)
{
throw new TimeZoneNotFoundException(
String.Format("The time zone '{0}' cannot be found.", tzName),
ex1);
}
catch (InvalidTimeZoneException ex2)
{
throw new InvalidTimeZoneException(
String.Format("The time zone {0} contains invalid data.", tzName),
ex2);
}
}
Private Sub HandleInnerException()
Dim timeZoneName As String = "Any Standard Time"
Dim tz As TimeZoneInfo
Try
tz = RetrieveTimeZone(timeZoneName)
Console.WriteLine("The time zone display name is {0}.", tz.DisplayName)
Catch e As TimeZoneNotFoundException
Console.WriteLine("{0} thrown by application", e.GetType().Name)
Console.WriteLine(" Message: {0}", e.Message)
If e.InnerException IsNot Nothing Then
Console.WriteLine(" Inner Exception Information:")
Dim innerEx As Exception = e.InnerException
Do
Console.WriteLine(" {0}: {1}", innerEx.GetType().Name, innerEx.Message)
innerEx = innerEx.InnerException
Loop While innerEx IsNot Nothing
End If
End Try
End Sub
Private Function RetrieveTimeZone(tzName As String) As TimeZoneInfo
Try
Return TimeZoneInfo.FindSystemTimeZoneById(tzName)
Catch ex1 As TimeZoneNotFoundException
Throw New TimeZoneNotFoundException( _
String.Format("The time zone '{0}' cannot be found.", tzName), _
ex1)
Catch ex2 As InvalidTimeZoneException
Throw New InvalidTimeZoneException( _
String.Format("The time zone {0} contains invalid data.", tzName), _
ex2)
End Try
End Function
注解
通常,可以使用 类的 InvalidTimeZoneException 此重载来处理 ... 中的 try异常。
catch 块。 参数 innerException 应该是对块中 catch 处理的异常对象的引用,也可以是 null。 然后,此值将 InvalidTimeZoneException 分配给 对象的 InnerException 属性。
字符串 message 分配给 Message 属性。 应针对当前区域性本地化字符串。