通过


InvalidTimeZoneException 构造函数

定义

初始化 InvalidTimeZoneException 类的新实例。

重载

名称 说明
InvalidTimeZoneException()

使用系统提供的消息初始化类的新实例 InvalidTimeZoneException

InvalidTimeZoneException(String)

使用指定的消息字符串初始化类的新实例 InvalidTimeZoneException

InvalidTimeZoneException(SerializationInfo, StreamingContext)
已过时.

从序列化的数据初始化类的新实例 InvalidTimeZoneException

InvalidTimeZoneException(String, Exception)

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

InvalidTimeZoneException()

Source:
InvalidTimeZoneException.cs
Source:
InvalidTimeZoneException.cs
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
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
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);
[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);
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}")>]
new InvalidTimeZoneException : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> InvalidTimeZoneException
new InvalidTimeZoneException : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> InvalidTimeZoneException
Protected Sub New (info As SerializationInfo, context As StreamingContext)

参数

info
SerializationInfo

包含序列化数据的对象。

context
StreamingContext

包含序列化数据的流。

属性

例外

参数 infonull.

-或-

参数 contextnull.

注解

代码不直接调用此构造函数来实例化 InvalidTimeZoneException 对象。 相反,从流反序列化InvalidTimeZoneException对象时,该对象的方法会调用IFormatterDeserialize它。

适用于

InvalidTimeZoneException(String, Exception)

Source:
InvalidTimeZoneException.cs
Source:
InvalidTimeZoneException.cs
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 表示中央标准时区的对象。 InvalidTimeZoneException如果在方法调用中RetrieveTimeZone发生异常,异常处理程序会将异常包装在新对象中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 属性。 字符串应本地化为当前区域性。

适用于