View Code
int number = int.MaxValue; Console.WriteLine(number); try { unchecked { number++; Console.WriteLine("超出数值范围"); } } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.WriteLine(number);
View Code
try { int num1 = int.Parse(txtNum1.Text); int num2 = int.Parse(txtNum2.Text); int result = num1 + num2; txtResult.Text = result.ToString(); } catch (FormatException fExt) { MessageBox.Show("该文本框只能输入数值"); } catch (OverflowException oExt) { MessageBox.Show("该文本框输入的数据过大或者过小"); txtResult.Text = "0"; } catch (Exception ex) { MessageBox.Show("有异常请注意你所输入的数据是否符合要求。"); //MessageBox.Show(ex.Message); }