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

Skip to content

Commit c48c971

Browse files
authored
DivideByZeroException F# snippets (#7599)
1 parent 3f6237c commit c48c971

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module exception1
2+
3+
// <Snippet1>
4+
open System
5+
6+
let number1 = 3000
7+
let number2 = 0
8+
try
9+
printfn $"{number1 / number2}"
10+
with :? DivideByZeroException ->
11+
printfn $"Division of {number1} by zero."
12+
13+
// The example displays the following output:
14+
// Division of 3000 by zero.
15+
// </Snippet1>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// <Snippet2>
2+
open System
3+
4+
let number1 = 3000.
5+
let number2 = 0.
6+
7+
printfn $"{number1 / number2}"
8+
9+
// The example displays the following output:
10+
// Infinity
11+
// </Snippet2>
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+
<ItemGroup>
7+
<Compile Include="exception1.fs" />
8+
<Compile Include="exception2.fs" />
9+
</ItemGroup>
10+
</Project>

xml/System/DivideByZeroException.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
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 <xref:System.DivideByZeroException> exception.
6161
6262
:::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.dividebyzeroexception.class/cs/exception2.cs" interactive="try-dotnet" id="Snippet2":::
63+
:::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.dividebyzeroexception.class/fs/exception2.fs" id="Snippet2":::
6364
:::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.dividebyzeroexception.class/vb/exception2.vb" id="Snippet2":::
6465
6566
For more information, see <xref:System.Single> and <xref:System.Double>.
@@ -84,6 +85,7 @@
8485
The following example handles a <xref:System.DivideByZeroException> exception in integer division.
8586
8687
:::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.dividebyzeroexception.class/cs/exception1.cs" interactive="try-dotnet" id="Snippet1":::
88+
:::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.dividebyzeroexception.class/fs/exception1.fs" id="Snippet1":::
8789
:::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.dividebyzeroexception.class/vb/exception1.vb" id="Snippet1":::
8890
8991
]]></format>

0 commit comments

Comments
 (0)