語言

TimeZoneNotFoundException 建構函式

定義

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

多載

名稱 Description
TimeZoneNotFoundException()

以系統提供的訊息初始化該 TimeZoneNotFoundException 類別的新實例。

TimeZoneNotFoundException(String)

初始化一個包含指定訊息字串的新 TimeZoneNotFoundException 類別實例。

TimeZoneNotFoundException(SerializationInfo, StreamingContext)
已淘汰.

從串行化數據初始化 TimeZoneNotFoundException 類別的新實例。

TimeZoneNotFoundException(String, Exception)

初始化類別的新實例 TimeZoneNotFoundException ,並附上指定的錯誤訊息及導致該異常的內部例外的參考。

TimeZoneNotFoundException()

來源:
TimeZoneNotFoundException.cs
來源:
TimeZoneNotFoundException.cs
來源:
TimeZoneNotFoundException.cs
來源:
TimeZoneNotFoundException.cs
來源:
TimeZoneNotFoundException.cs

以系統提供的訊息初始化該 TimeZoneNotFoundException 類別的新實例。

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

備註

這是類別的 TimeZoneNotFoundException 無參數建構子。 此建構器會將新實例的屬性初始 Message 化為系統提供的訊息,描述錯誤,例如「本地電腦未找到時區 'timeZoneName'」。此訊息是針對當前系統文化在地化的。

適用於

TimeZoneNotFoundException(String)

來源:
TimeZoneNotFoundException.cs
來源:
TimeZoneNotFoundException.cs
來源:
TimeZoneNotFoundException.cs
來源:
TimeZoneNotFoundException.cs
來源:
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)

來源:
TimeZoneNotFoundException.cs
來源:
TimeZoneNotFoundException.cs
來源:
TimeZoneNotFoundException.cs
來源:
TimeZoneNotFoundException.cs
來源:
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);
[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);
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}")>]
new TimeZoneNotFoundException : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> TimeZoneNotFoundException
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 。 相反地,物件的方法會在將物件從串流中反序列化IFormatter時呼叫。DeserializeTimeZoneNotFoundException

適用於

TimeZoneNotFoundException(String, Exception)

來源:
TimeZoneNotFoundException.cs
來源:
TimeZoneNotFoundException.cs
來源:
TimeZoneNotFoundException.cs
來源:
TimeZoneNotFoundException.cs
來源:
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 屬性。 字串應該針對當前文化進行局部化。

適用於