TimeZoneNotFoundException Konstruktory

Definicja

Inicjuje nowe wystąpienie klasy TimeZoneNotFoundException.

Przeciążenia

TimeZoneNotFoundException()

Inicjuje TimeZoneNotFoundException nowe wystąpienie klasy z komunikatem dostarczonym przez system.

TimeZoneNotFoundException(String)

Inicjuje TimeZoneNotFoundException nowe wystąpienie klasy z określonym ciągiem komunikatu.

TimeZoneNotFoundException(SerializationInfo, StreamingContext)
Przestarzałe.

Inicjuje TimeZoneNotFoundException nowe wystąpienie klasy z serializacji danych.

TimeZoneNotFoundException(String, Exception)

Inicjuje nowe wystąpienie TimeZoneNotFoundException klasy z określonym komunikatem o błędzie i odwołaniem do wewnętrznego wyjątku, który jest przyczyną tego wyjątku.

TimeZoneNotFoundException()

Źródło:
TimeZoneNotFoundException.cs
Źródło:
TimeZoneNotFoundException.cs
Źródło:
TimeZoneNotFoundException.cs

Inicjuje TimeZoneNotFoundException nowe wystąpienie klasy z komunikatem dostarczonym przez system.

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

Uwagi

Jest to konstruktor bez parametrów TimeZoneNotFoundException klasy. Ten konstruktor inicjuje Message właściwość nowego wystąpienia do dostarczonego przez system komunikatu opisującego błąd, taki jak "Strefa czasowa 'timeZoneName' nie została znaleziona na komputerze lokalnym". Ten komunikat jest zlokalizowany dla bieżącej kultury systemu.

Dotyczy

TimeZoneNotFoundException(String)

Źródło:
TimeZoneNotFoundException.cs
Źródło:
TimeZoneNotFoundException.cs
Źródło:
TimeZoneNotFoundException.cs

Inicjuje TimeZoneNotFoundException nowe wystąpienie klasy z określonym ciągiem komunikatu.

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

Parametry

message
String

Ciąg opisujący wyjątek.

Uwagi

Ciąg message jest przypisywany do Message właściwości. Ciąg powinien być zlokalizowany dla bieżącej kultury.

Dotyczy

TimeZoneNotFoundException(SerializationInfo, StreamingContext)

Źródło:
TimeZoneNotFoundException.cs
Źródło:
TimeZoneNotFoundException.cs
Źródło:
TimeZoneNotFoundException.cs

Przestroga

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

Inicjuje TimeZoneNotFoundException nowe wystąpienie klasy z serializacji danych.

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)

Parametry

info
SerializationInfo

Obiekt zawierający dane serializowane.

context
StreamingContext

Strumień zawierający dane serializowane.

Atrybuty

Wyjątki

Parametr info to null.

-lub-

Parametr context to null.

Uwagi

Ten konstruktor nie jest wywoływany bezpośrednio przez kod w celu utworzenia TimeZoneNotFoundException wystąpienia obiektu. Zamiast tego jest wywoływana przez IFormatter metodę obiektu Deserialize podczas deserializacji TimeZoneNotFoundException obiektu ze strumienia.

Dotyczy

TimeZoneNotFoundException(String, Exception)

Źródło:
TimeZoneNotFoundException.cs
Źródło:
TimeZoneNotFoundException.cs
Źródło:
TimeZoneNotFoundException.cs

Inicjuje nowe wystąpienie TimeZoneNotFoundException klasy z określonym komunikatem o błędzie i odwołaniem do wewnętrznego wyjątku, który jest przyczyną tego wyjątku.

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)

Parametry

message
String

Ciąg opisujący wyjątek.

innerException
Exception

Wyjątek będący przyczyną bieżącego wyjątku.

Przykłady

Poniższy przykład próbuje pobrać nieistniejący strefę czasową, która zgłasza błąd TimeZoneNotFoundException. Procedura obsługi wyjątków opakowuje wyjątek w nowym TimeZoneNotFoundException obiekcie, który program obsługi wyjątków powraca do obiektu wywołującego. Następnie program obsługi wyjątków wywołującego wyświetla informacje o wyjątku zewnętrznym i wewnętrznym.

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

Uwagi

Zazwyczaj to przeciążenie jest używane TimeZoneNotFoundException do obsługi wyjątku tryw ...catch Bloku. Parametr innerException powinien być odwołaniem do obiektu wyjątku obsługiwanego catch w bloku lub może to być null. Ta wartość jest następnie przypisywana InnerException do TimeZoneNotFoundException właściwości obiektu.

Ciąg message jest przypisywany do Message właściwości. Ciąg powinien być zlokalizowany dla bieżącej kultury.

Dotyczy