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

Skip to content

System.DivideByZeroException F# snippets #7599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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,15 @@
module exception1

// <Snippet1>
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.
// </Snippet1>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// <Snippet2>
open System

let number1 = 3000.
let number2 = 0.

printfn $"{number1 / number2}"

// The example displays the following output:
// Infinity
// </Snippet2>
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="exception1.fs" />
<Compile Include="exception2.fs" />
</ItemGroup>
</Project>
2 changes: 2 additions & 0 deletions xml/System/DivideByZeroException.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <xref:System.DivideByZeroException> 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 <xref:System.Single> and <xref:System.Double>.
Expand All @@ -84,6 +85,7 @@
The following example handles a <xref:System.DivideByZeroException> 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":::

]]></format>
Expand Down