InvalidTimeZoneException Constructeurs

Définition

Initialise une nouvelle instance de la classe InvalidTimeZoneException.

Surcharges

InvalidTimeZoneException()

Initialise une nouvelle instance de la classe InvalidTimeZoneException avec un message système.

InvalidTimeZoneException(String)

Initialise une nouvelle instance de la classe InvalidTimeZoneException avec la chaîne de message spécifiée.

InvalidTimeZoneException(SerializationInfo, StreamingContext)
Obsolète.

Initialise une nouvelle instance de la classe InvalidTimeZoneException à partir de données sérialisées.

InvalidTimeZoneException(String, Exception)

Initialise une nouvelle instance de la classe InvalidTimeZoneException avec un message d'erreur spécifié et une référence à l'exception interne ayant provoqué cette exception.

InvalidTimeZoneException()

Source:
InvalidTimeZoneException.cs
Source:
InvalidTimeZoneException.cs
Source:
InvalidTimeZoneException.cs

Initialise une nouvelle instance de la classe InvalidTimeZoneException avec un message système.

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

Remarques

Il s’agit du constructeur sans paramètre de la InvalidTimeZoneException classe . Il initialise la Message propriété du nouveau instance dans un message fourni par le système qui décrit l’erreur, par exemple « L’exception de type 'System.InvalidTimeZoneException' a été levée ». Ce message est localisé pour la culture système actuelle.

S’applique à

InvalidTimeZoneException(String)

Source:
InvalidTimeZoneException.cs
Source:
InvalidTimeZoneException.cs
Source:
InvalidTimeZoneException.cs

Initialise une nouvelle instance de la classe InvalidTimeZoneException avec la chaîne de message spécifiée.

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

Paramètres

message
String

Chaîne qui décrit l’exception.

Remarques

La chaîne fournie comme message paramètre est affectée à la Message propriété . Il doit être localisé pour la culture actuelle.

S’applique à

InvalidTimeZoneException(SerializationInfo, StreamingContext)

Source:
InvalidTimeZoneException.cs
Source:
InvalidTimeZoneException.cs
Source:
InvalidTimeZoneException.cs

Attention

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

Initialise une nouvelle instance de la classe InvalidTimeZoneException à partir de données sérialisées.

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

Paramètres

info
SerializationInfo

Objet qui contient les données sérialisées.

context
StreamingContext

Flux qui contient les données sérialisées.

Attributs

Exceptions

Le paramètre info a la valeur null.

- ou -

Le paramètre context a la valeur null.

Remarques

Ce constructeur n’est pas appelé directement par votre code pour instancier l’objet InvalidTimeZoneException . Au lieu de cela, il est appelé par la méthode de l’objet IFormatter lors de Deserialize la désérialisation de l’objet InvalidTimeZoneException à partir d’un flux.

S’applique à

InvalidTimeZoneException(String, Exception)

Source:
InvalidTimeZoneException.cs
Source:
InvalidTimeZoneException.cs
Source:
InvalidTimeZoneException.cs

Initialise une nouvelle instance de la classe InvalidTimeZoneException avec un message d'erreur spécifié et une référence à l'exception interne ayant provoqué cette exception.

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

Paramètres

message
String

Chaîne qui décrit l’exception.

innerException
Exception

Exception ayant provoqué l'exception actuelle.

Exemples

Le code suivant tente de récupérer un TimeZoneInfo objet qui représente le fuseau horaire standard central. Si un InvalidTimeZoneException se produit dans l’appel RetrieveTimeZone de méthode, le gestionnaire d’exceptions encapsule l’exception dans un nouvel InvalidTimeZoneException objet, qu’il retourne à l’appelant. Le gestionnaire d’exceptions de l’appelant affiche ensuite des informations sur les exceptions externes et internes.

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

Remarques

En règle générale, vous utilisez cette surcharge de la InvalidTimeZoneException classe pour gérer une exception dans un try...catch Bloc. Le innerException paramètre doit être une référence à l’objet d’exception géré dans le catch bloc, ou il peut être null. Cette valeur est ensuite affectée à la propriété de l’objet InvalidTimeZoneExceptionInnerException .

La message chaîne est affectée à la Message propriété . La chaîne doit être localisée pour la culture actuelle.

S’applique à