Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d0e277b

Browse files
authored
TimeZoneNotFoundException F# snippet (#7917)
1 parent ead3f1a commit d0e277b

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// <Snippet1>
2+
open System
3+
4+
let retrieveTimeZone tzName =
5+
try
6+
TimeZoneInfo.FindSystemTimeZoneById tzName
7+
with
8+
| :? TimeZoneNotFoundException as ex1 ->
9+
raise (TimeZoneNotFoundException($"The time zone '{tzName}' cannot be found.", ex1) )
10+
| :? InvalidTimeZoneException as ex2 ->
11+
raise (InvalidTimeZoneException($"The time zone {tzName} contains invalid data.", ex2) )
12+
13+
let handleInnerException () =
14+
let timeZoneName = "Any Standard Time"
15+
try
16+
let tz = retrieveTimeZone timeZoneName
17+
printfn $"The time zone display name is {tz.DisplayName}."
18+
with :? TimeZoneNotFoundException as e ->
19+
printfn $"{e.GetType().Name} thrown by application"
20+
printfn $" Message: {e.Message}"
21+
if e.InnerException <> null then
22+
printfn " Inner Exception Information:"
23+
let rec printInner (innerEx: exn) =
24+
if innerEx <> null then
25+
printfn $" {innerEx.GetType().Name}: {innerEx.Message}"
26+
printInner innerEx.InnerException
27+
printInner e
28+
// </Snippet1>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFramework>net6.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<Compile Include="TimeZoneNotFoundException.fs" />
9+
</ItemGroup>
10+
</Project>

xml/System/TimeZoneNotFoundException.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@
291291
The following example tries to retrieve a nonexistent time zone, which throws a <xref:System.TimeZoneNotFoundException>. The exception handler wraps the exception in a new <xref:System.TimeZoneNotFoundException> object, which the exception handler returns to the caller. The caller's exception handler then displays information about both the outer and inner exception.
292292
293293
:::code language="csharp" source="~/snippets/csharp/System/InvalidTimeZoneException/.ctor/TimeZoneNotFoundException.cs" id="Snippet1":::
294+
:::code language="fsharp" source="~/snippets/fsharp/System/InvalidTimeZoneException/.ctor/TimeZoneNotFoundException.fs" id="Snippet1":::
294295
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZoneNotFoundException.Class/vb/TimeZoneNotFoundException.vb" id="Snippet1":::
295296
296297
]]></format>

0 commit comments

Comments
 (0)