TimeZoneNotFoundException 建構函式

定義

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

多載

TimeZoneNotFoundException()

使用系統提供的錯誤,初始化 TimeZoneNotFoundException 類別的新執行個體。

TimeZoneNotFoundException(String)

使用指定的訊息字串,初始化 TimeZoneNotFoundException 類別的新執行個體。

TimeZoneNotFoundException(SerializationInfo, StreamingContext)
已淘汰.

從序列化資料中,初始化 TimeZoneNotFoundException 類別的新執行個體。

TimeZoneNotFoundException(String, Exception)

使用指定的錯誤訊息以及造成此例外狀況的內部例外狀況的參考,初始化 TimeZoneNotFoundException 類別的新執行個體。

TimeZoneNotFoundException()

來源:
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 類別的新執行個體。

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

警告

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)

來源:
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 多載來處理 ... 中的例外狀況 trycatch 塊。 參數 innerException 應該是區塊中 catch 處理之例外狀況物件的參考,或者它可以是 null 。 這個值接著會指派給 TimeZoneNotFoundException 物件的 InnerException 屬性。

字串 message 會指派給 Message 屬性。 字串應該針對目前的文化特性進行當地語系化。

適用於