diff --git a/snippets/fsharp/System/InvalidTimeZoneException/.ctor/TimeZoneNotFoundException.fs b/snippets/fsharp/System/InvalidTimeZoneException/.ctor/TimeZoneNotFoundException.fs new file mode 100644 index 00000000000..f0b3e3b47cc --- /dev/null +++ b/snippets/fsharp/System/InvalidTimeZoneException/.ctor/TimeZoneNotFoundException.fs @@ -0,0 +1,28 @@ +// +open System + +let retrieveTimeZone tzName = + try + TimeZoneInfo.FindSystemTimeZoneById tzName + with + | :? TimeZoneNotFoundException as ex1 -> + raise (TimeZoneNotFoundException($"The time zone '{tzName}' cannot be found.", ex1) ) + | :? InvalidTimeZoneException as ex2 -> + raise (InvalidTimeZoneException($"The time zone {tzName} contains invalid data.", ex2) ) + +let handleInnerException () = + let timeZoneName = "Any Standard Time" + try + let tz = retrieveTimeZone timeZoneName + printfn $"The time zone display name is {tz.DisplayName}." + with :? TimeZoneNotFoundException as e -> + printfn $"{e.GetType().Name} thrown by application" + printfn $" Message: {e.Message}" + if e.InnerException <> null then + printfn " Inner Exception Information:" + let rec printInner (innerEx: exn) = + if innerEx <> null then + printfn $" {innerEx.GetType().Name}: {innerEx.Message}" + printInner innerEx.InnerException + printInner e +// \ No newline at end of file diff --git a/snippets/fsharp/System/InvalidTimeZoneException/.ctor/fs.fsproj b/snippets/fsharp/System/InvalidTimeZoneException/.ctor/fs.fsproj new file mode 100644 index 00000000000..1e3b3626ca0 --- /dev/null +++ b/snippets/fsharp/System/InvalidTimeZoneException/.ctor/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/xml/System/TimeZoneNotFoundException.xml b/xml/System/TimeZoneNotFoundException.xml index 706abd60135..df831178517 100644 --- a/xml/System/TimeZoneNotFoundException.xml +++ b/xml/System/TimeZoneNotFoundException.xml @@ -291,6 +291,7 @@ The following example tries to retrieve a nonexistent time zone, which throws a . The exception handler wraps the exception in a new object, which the exception handler returns to the caller. The caller's exception handler then displays information about both the outer and inner exception. :::code language="csharp" source="~/snippets/csharp/System/InvalidTimeZoneException/.ctor/TimeZoneNotFoundException.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/InvalidTimeZoneException/.ctor/TimeZoneNotFoundException.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZoneNotFoundException.Class/vb/TimeZoneNotFoundException.vb" id="Snippet1"::: ]]>