No 56 · 如何处理“溢出”错误

 
static int x = int.MinValue;  // Max int value
        static int y = int.MinValue;  // Max int value
       
        int CheckedMethod()
        {
            int z = 0;
            try
            {
                z = checked((int)(x + y));
            }
            catch (System.OverflowException e)
            {
               MessageBox.Show(e.ToString());
            }
            return z;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            CheckedMethod();
        }

你可能感兴趣的:(object,button)