How can I make the Visual studio to throw an integer overflow exception?
I know I can use a checked statement explicitly. But I want to make this behavior default in my solution (at least during debugging).
int bigNumber= 12345;
byte overflowException = (byte)(bigNumber); //want to see an exception here
According to the docs there is a
/checkedcompiler option for turning this on as default.In the project properties for the project, go to the “Build” tab and click the “Advanced…” button. On this window is a “Check for arithmetic overflow/underflow” checkbox:
As an aside, the second set of brackets in
(byte)(bigNumber)are not required:(byte)bigNumber.