TimeZoneNotFoundException Construtores

Definição

Inicializa uma nova instância da classe TimeZoneNotFoundException.Initializes a new instance of the TimeZoneNotFoundException class.

Sobrecargas

TimeZoneNotFoundException()

Inicializa uma nova instância da classe TimeZoneNotFoundException com uma mensagem fornecida pelo sistema.Initializes a new instance of the TimeZoneNotFoundException class with a system-supplied message.

TimeZoneNotFoundException(String)

Inicializa uma nova instância da classe TimeZoneNotFoundException com a cadeia de caracteres de mensagem especificada.Initializes a new instance of the TimeZoneNotFoundException class with the specified message string.

TimeZoneNotFoundException(SerializationInfo, StreamingContext)

Inicializa uma nova instância da classe TimeZoneNotFoundException com base nos dados serializados.Initializes a new instance of the TimeZoneNotFoundException class from serialized data.

TimeZoneNotFoundException(String, Exception)

Inicializa uma nova instância da classe TimeZoneNotFoundException com uma mensagem de erro especificada e uma referência à exceção interna que é a causa da exceção.Initializes a new instance of the TimeZoneNotFoundException class with a specified error message and a reference to the inner exception that is the cause of this exception.

TimeZoneNotFoundException()

Inicializa uma nova instância da classe TimeZoneNotFoundException com uma mensagem fornecida pelo sistema.Initializes a new instance of the TimeZoneNotFoundException class with a system-supplied message.

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

Comentários

Esse é o construtor sem parâmetros da TimeZoneNotFoundException classe.This is the parameterless constructor of the TimeZoneNotFoundException class. Esse construtor inicializa a Message propriedade da nova instância para uma mensagem fornecida pelo sistema que descreve o erro, como "o fuso horário 'timeZoneName' não foi encontrado no computador local."This constructor initializes the Message property of the new instance to a system-supplied message that describes the error, such as "The time zone 'timeZoneName' was not found on the local computer." Esta mensagem é localizada para a cultura do sistema atual.This message is localized for the current system culture.

Aplica-se a

TimeZoneNotFoundException(String)

Inicializa uma nova instância da classe TimeZoneNotFoundException com a cadeia de caracteres de mensagem especificada.Initializes a new instance of the TimeZoneNotFoundException class with the specified message string.

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

Parâmetros

message
String

Uma cadeia de caracteres que descreve a exceção.A string that describes the exception.

Comentários

A message cadeia de caracteres é atribuída à Message propriedade.The message string is assigned to the Message property. A cadeia de caracteres deve ser localizada para a cultura atual.The string should be localized for the current culture.

Aplica-se a

TimeZoneNotFoundException(SerializationInfo, StreamingContext)

Inicializa uma nova instância da classe TimeZoneNotFoundException com base nos dados serializados.Initializes a new instance of the TimeZoneNotFoundException class from serialized data.

protected:
 TimeZoneNotFoundException(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);
protected TimeZoneNotFoundException (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
new TimeZoneNotFoundException : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> TimeZoneNotFoundException
Protected Sub New (info As SerializationInfo, context As StreamingContext)

Parâmetros

info
SerializationInfo

O objeto que contém os dados serializados.The object that contains the serialized data.

context
StreamingContext

O fluxo que contém os dados serializados.The stream that contains the serialized data.

Exceções

O parâmetro info é null.The info parameter is null.

- ou --or- O parâmetro context é null.The context parameter is null.

Comentários

Esse construtor não é chamado diretamente pelo seu código para instanciar o TimeZoneNotFoundException objeto.This constructor is not called directly by your code to instantiate the TimeZoneNotFoundException object. Em vez disso, ele é chamado pelo IFormatter método do objeto Deserialize ao desserializar o TimeZoneNotFoundException objeto de um fluxo.Instead, it is called by the IFormatter object's Deserialize method when deserializing the TimeZoneNotFoundException object from a stream.

Aplica-se a

TimeZoneNotFoundException(String, Exception)

Inicializa uma nova instância da classe TimeZoneNotFoundException com uma mensagem de erro especificada e uma referência à exceção interna que é a causa da exceção.Initializes a new instance of the TimeZoneNotFoundException class with a specified error message and a reference to the inner exception that is the cause of this exception.

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)

Parâmetros

message
String

Uma cadeia de caracteres que descreve a exceção.A string that describes the exception.

innerException
Exception

A exceção que é a causa da exceção atual.The exception that is the cause of the current exception.

Exemplos

O exemplo a seguir tenta recuperar um fuso horário inexistente, que gera um TimeZoneNotFoundException .The following example tries to retrieve a nonexistent time zone, which throws a TimeZoneNotFoundException. O manipulador de exceção encapsula a exceção em um novo TimeZoneNotFoundException objeto, que o manipulador de exceção retorna ao chamador.The exception handler wraps the exception in a new TimeZoneNotFoundException object, which the exception handler returns to the caller. O manipulador de exceção do chamador exibe informações sobre a exceção externa e interna.The caller's exception handler then displays information about both the outer and inner exception.

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

Comentários

Normalmente, você usa essa TimeZoneNotFoundException sobrecarga para manipular uma exceção em um try ...catchTypically, you use this TimeZoneNotFoundException overload to handle an exception in a trycatch impeça.block. O innerException parâmetro deve ser uma referência ao objeto de exceção manipulado no catch bloco ou pode ser null .The innerException parameter should be a reference to the exception object handled in the catch block, or it can be null. Esse valor é então atribuído à TimeZoneNotFoundException Propriedade do objeto InnerException .This value is then assigned to the TimeZoneNotFoundException object's InnerException property.

A message cadeia de caracteres é atribuída à Message propriedade.The message string is assigned to the Message property. A cadeia de caracteres deve ser localizada para a cultura atual.The string should be localized for the current culture.

Aplica-se a