From 8d00ce1dbcff5f02fc1d31b41fcaca5f1f9894d5 Mon Sep 17 00:00:00 2001 From: albert-du <52804499+albert-du@users.noreply.github.com> Date: Sat, 15 Jan 2022 14:34:17 -0800 Subject: [PATCH] DivideByZeroException F# snippets --- .../fs/exception1.fs | 15 +++++++++++++++ .../fs/exception2.fs | 11 +++++++++++ .../fs/fs.fsproj | 10 ++++++++++ xml/System/DivideByZeroException.xml | 2 ++ 4 files changed, 38 insertions(+) create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.dividebyzeroexception.class/fs/exception1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.dividebyzeroexception.class/fs/exception2.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.dividebyzeroexception.class/fs/fs.fsproj diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.dividebyzeroexception.class/fs/exception1.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.dividebyzeroexception.class/fs/exception1.fs new file mode 100644 index 00000000000..e1b3c7f6b08 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.dividebyzeroexception.class/fs/exception1.fs @@ -0,0 +1,15 @@ +module exception1 + +// +open System + +let number1 = 3000 +let number2 = 0 +try + printfn $"{number1 / number2}" +with :? DivideByZeroException -> + printfn $"Division of {number1} by zero." + +// The example displays the following output: +// Division of 3000 by zero. +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.dividebyzeroexception.class/fs/exception2.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.dividebyzeroexception.class/fs/exception2.fs new file mode 100644 index 00000000000..df2dd99a71f --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.dividebyzeroexception.class/fs/exception2.fs @@ -0,0 +1,11 @@ +// +open System + +let number1 = 3000. +let number2 = 0. + +printfn $"{number1 / number2}" + +// The example displays the following output: +// Infinity +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.dividebyzeroexception.class/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.dividebyzeroexception.class/fs/fs.fsproj new file mode 100644 index 00000000000..0a54fa777d4 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.dividebyzeroexception.class/fs/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/xml/System/DivideByZeroException.xml b/xml/System/DivideByZeroException.xml index 1c34b87ad41..552cbea5c73 100644 --- a/xml/System/DivideByZeroException.xml +++ b/xml/System/DivideByZeroException.xml @@ -60,6 +60,7 @@ Dividing a floating-point value by zero doesn't throw an exception; it results in positive infinity, negative infinity, or not a number (NaN), according to the rules of IEEE 754 arithmetic. Because the following example uses floating-point division rather than integer division, the operation does not throw a exception. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.dividebyzeroexception.class/cs/exception2.cs" interactive="try-dotnet" id="Snippet2"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.dividebyzeroexception.class/fs/exception2.fs" id="Snippet2"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.dividebyzeroexception.class/vb/exception2.vb" id="Snippet2"::: For more information, see and . @@ -84,6 +85,7 @@ The following example handles a exception in integer division. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.dividebyzeroexception.class/cs/exception1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.dividebyzeroexception.class/fs/exception1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.dividebyzeroexception.class/vb/exception1.vb" id="Snippet1"::: ]]>