如何讓Visual Studio拋出整數溢出異常? 我知道我可以明確地使用checked
語句。但我想在我的解決方案中使這種行爲默認(至少在調試過程中)。捕獲Visual Studio中的整數溢出異常
int bigNumber= 12345;
byte overflowException = (byte)(bigNumber); //want to see an exception here
如何讓Visual Studio拋出整數溢出異常? 我知道我可以明確地使用checked
語句。但我想在我的解決方案中使這種行爲默認(至少在調試過程中)。捕獲Visual Studio中的整數溢出異常
int bigNumber= 12345;
byte overflowException = (byte)(bigNumber); //want to see an exception here
可能的重複http://stackoverflow.com/questions/2772379/making-sure-unsigned-int-long-always-execute-in-checked-context-in-c-sharp - 但看看這裏因爲第一個答案可能會回答你的問題 – Rawling 2012-07-13 09:35:07
@Rawling這絕對是最終答案的重複,但在上述問題標題中輸入並不能找到它。所以在這裏留下一點點價值。 – 2012-07-13 09:41:57