InvalidTimeZoneException 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 InvalidTimeZoneException 類別的新執行個體。
多載
| 名稱 | Description |
|---|---|
| InvalidTimeZoneException() |
以系統提供的訊息初始化該 InvalidTimeZoneException 類別的新實例。 |
| InvalidTimeZoneException(String) |
初始化一個包含指定訊息字串的新 InvalidTimeZoneException 類別實例。 |
| InvalidTimeZoneException(SerializationInfo, StreamingContext) |
已淘汰.
從串行化數據初始化 InvalidTimeZoneException 類別的新實例。 |
| InvalidTimeZoneException(String, Exception) |
初始化類別的新實例 InvalidTimeZoneException ,並附上指定的錯誤訊息及導致該異常的內部例外的參考。 |
InvalidTimeZoneException()
以系統提供的訊息初始化該 InvalidTimeZoneException 類別的新實例。
public:
InvalidTimeZoneException();
public InvalidTimeZoneException();
Public Sub New ()
備註
這是類別的 InvalidTimeZoneException 無參數建構子。 它會將新實例的屬性初始 Message 化為系統提供的訊息,描述錯誤,例如「Exception of type 'System.InvalidTimeZoneException' was thrown.」。此訊息是針對當前系統文化在地化的。
適用於
InvalidTimeZoneException(String)
初始化一個包含指定訊息字串的新 InvalidTimeZoneException 類別實例。
public:
InvalidTimeZoneException(System::String ^ message);
public InvalidTimeZoneException(string message);
public InvalidTimeZoneException(string? message);
new InvalidTimeZoneException : string -> InvalidTimeZoneException
Public Sub New (message As String)
參數
- message
- String
一個描述例外的字串。
備註
參數所提供的 message 字串會被指派到屬性 Message 上。 它應該根據當前的文化進行在地化。
適用於
InvalidTimeZoneException(SerializationInfo, StreamingContext)
警告
This API supports obsolete formatter-based serialization. It should not be called or extended by application code.
從串行化數據初始化 InvalidTimeZoneException 類別的新實例。
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);
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}")>]
new InvalidTimeZoneException : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> InvalidTimeZoneException
new InvalidTimeZoneException : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> InvalidTimeZoneException
Protected Sub New (info As SerializationInfo, context As StreamingContext)
參數
- info
- SerializationInfo
包含序列化資料的物件。
- context
- StreamingContext
包含序列化資料的串流。
- 屬性
例外狀況
備註
這個建構子不會被你的程式碼直接呼叫來實例化物件 InvalidTimeZoneException 。 相反地,物件的方法會在將物件從串流中反序列化InvalidTimeZoneException時呼叫。IFormatterDeserialize
適用於
InvalidTimeZoneException(String, Exception)
初始化類別的新實例 InvalidTimeZoneException ,並附上指定的錯誤訊息及導致該異常的內部例外的參考。
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)
參數
- message
- String
一個描述例外的字串。
- innerException
- Exception
該例外即為當前例外的原因。
範例
以下程式碼嘗試擷取 TimeZoneInfo 代表中央標準時區的物件。 若 發生在 InvalidTimeZoneException 方法呼叫中 RetrieveTimeZone ,例外處理器會將該異常包裹成一個新 InvalidTimeZoneException 物件,並返回給呼叫者。 呼叫者的例外處理器會顯示外部與內部例外的資訊。
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
備註
通常,你會利用這個類別的 InvalidTimeZoneException 過載來處理 try...
catch 阻擋。
innerException參數應為區塊中處理catch的例外物件的參考,或是 null。 這個值接著被賦予 InvalidTimeZoneException 物件的 InnerException 屬性。
該 message 字串被指派給該 Message 屬性。 字串應該針對當前文化進行局部化。