TimeZoneNotFoundException 构造函数

定义

初始化 TimeZoneNotFoundException 类的新实例。

重载

TimeZoneNotFoundException()

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

TimeZoneNotFoundException(String)

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

TimeZoneNotFoundException(SerializationInfo, StreamingContext)
已过时.

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

TimeZoneNotFoundException(String, Exception)

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

TimeZoneNotFoundException()

Source:
TimeZoneNotFoundException.cs
Source:
TimeZoneNotFoundException.cs
Source:
TimeZoneNotFoundException.cs

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

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

注解

这是 类的 TimeZoneNotFoundException 无参数构造函数。 此构造函数将 Message 新 实例的 属性初始化为系统提供的消息,该消息描述错误,例如“在本地计算机上找不到时区 'timeZoneName'”。此消息已针对当前系统区域性进行本地化。

适用于

TimeZoneNotFoundException(String)

Source:
TimeZoneNotFoundException.cs
Source:
TimeZoneNotFoundException.cs
Source:
TimeZoneNotFoundException.cs

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

public:
 TimeZoneNotFoundException(System::String ^ message);
public TimeZoneNotFoundException (string? message);
public TimeZoneNotFoundException (string message);
new TimeZoneNotFoundException : string -> TimeZoneNotFoundException
Public Sub New (message As String)

参数

message
String

描述异常的字符串。

注解

字符串 message 分配给 Message 属性。 应针对当前区域性本地化字符串。

适用于

TimeZoneNotFoundException(SerializationInfo, StreamingContext)

Source:
TimeZoneNotFoundException.cs
Source:
TimeZoneNotFoundException.cs
Source:
TimeZoneNotFoundException.cs

注意

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

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

protected:
 TimeZoneNotFoundException(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);
protected TimeZoneNotFoundException (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 TimeZoneNotFoundException (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
new TimeZoneNotFoundException : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> TimeZoneNotFoundException
[<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 TimeZoneNotFoundException : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> TimeZoneNotFoundException
Protected Sub New (info As SerializationInfo, context As StreamingContext)

参数

info
SerializationInfo

包含序列化数据的对象。

context
StreamingContext

包含序列化数据的流。

属性

例外

info 参数为 null

- 或 -

context 参数为 null

注解

代码不直接调用此构造函数来实例化对象 TimeZoneNotFoundException 。 相反,当从流反序列化TimeZoneNotFoundException对象Deserialize时,IFormatter由 对象的 方法调用它。

适用于

TimeZoneNotFoundException(String, Exception)

Source:
TimeZoneNotFoundException.cs
Source:
TimeZoneNotFoundException.cs
Source:
TimeZoneNotFoundException.cs

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

public:
 TimeZoneNotFoundException(System::String ^ message, Exception ^ innerException);
public TimeZoneNotFoundException (string? message, Exception? innerException);
public TimeZoneNotFoundException (string message, Exception innerException);
new TimeZoneNotFoundException : string * Exception -> TimeZoneNotFoundException
Public Sub New (message As String, innerException As Exception)

参数

message
String

描述异常的字符串。

innerException
Exception

导致当前异常的异常。

示例

以下示例尝试检索不存在的时区,这会引发 TimeZoneNotFoundException。 异常处理程序将异常包装在一个新的 TimeZoneNotFoundException 对象中,异常处理程序将它返回给调用方。 然后,调用方异常处理程序会显示有关外部异常和内部异常的信息。

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); 
   }      
}
open System

let retrieveTimeZone tzName =
    try
        TimeZoneInfo.FindSystemTimeZoneById tzName
    with 
    | :? TimeZoneNotFoundException as ex1 ->
        raise (TimeZoneNotFoundException($"The time zone '{tzName}' cannot be found.", ex1) )
    | :? InvalidTimeZoneException as ex2 ->
        raise (InvalidTimeZoneException($"The time zone {tzName} contains invalid data.", ex2) )

let handleInnerException () =
    let timeZoneName = "Any Standard Time"
    try
        let tz = retrieveTimeZone timeZoneName
        printfn $"The time zone display name is {tz.DisplayName}."
    with :? TimeZoneNotFoundException as e ->
        printfn $"{e.GetType().Name} thrown by application"
        printfn $"   Message: {e.Message}" 
        if e.InnerException <> null then
            printfn "   Inner Exception Information:"
            let rec printInner (innerEx: exn) =
                if innerEx <> null then
                    printfn $"      {innerEx.GetType().Name}: {innerEx.Message}"
                    printInner innerEx.InnerException
            printInner e
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

注解

通常,使用此 TimeZoneNotFoundException 重载来处理 ... 中的 try异常 catch 块。 参数 innerException 应该是对 块中 catch 处理的异常对象的引用,也可以是 null。 然后,此值将 TimeZoneNotFoundException 分配给对象的 InnerException 属性。

字符串 message 分配给 Message 属性。 应针对当前区域性本地化字符串。

适用于