Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// <Snippet1>
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
// </Snippet1>
10 changes: 10 additions & 0 deletions snippets/fsharp/System/InvalidTimeZoneException/.ctor/fs.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Include="TimeZoneNotFoundException.fs" />
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions xml/System/TimeZoneNotFoundException.xml
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@
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.

:::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":::

]]></format>
Expand Down