本文整理汇总了C#中System.TimeZoneNotFoundException.TimeZoneNotFoundException构造函数的典型用法代码示例。如果您正苦于以下问题:C# TimeZoneNotFoundException构造函数的具体用法?C# TimeZoneNotFoundException怎么用?C# TimeZoneNotFoundException使用的例子?那么, 这里精选的构造函数代码示例或许可以为您提供帮助。
在下文中一共展示了TimeZoneNotFoundException构造函数的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleInnerException
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);
}
}