dotnet / dotnet/dotnet-api-docs
OverflowException ignores special case for division by -1
- Dominant language
- C#
- Stars
- 949
- Forks
- 1.7k
- Avg merge
- 3d 27m
- Merged PRs (30d)
- 49
Description
**Location of Issue**
URL - https://docs.microsoft.com/en-us/dotnet/api/system.overflowexception
Source - https://github.com/dotnet/dotnet-api-docs/blob/master/xml/System/OverflowException.xml
**Issue description**
The documentation states that arithmetic operations will not throw an OverflowException, unless in a checked context. However, there is one (implementation-defined exception) to this rule, documented at https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/expressions#division-operator :
> In an unchecked context, it is implementation-defined as to whether a System.ArithmeticException (or a subclass thereof) is thrown or the overflow goes unreported with the resulting value being that of the left operand.
**Example**
On modern Intel CPUs, the below code will throw an exception:
unchecked
{
int a = Int32.MinValue;
int b = -1;
int c = a/b;
}
**Relevant quote within the documentation**
> For the arithmetic, casting, or conversion operation to throw an OverflowException, the operation must occur in a checked context.
**Target framework**
All
Contributor guide
Assessment
This issue has not been assessed yet.