丶使用 checked 关键字处理 溢出 错误信息
2011-10-17 01:25
176 查看
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Example22
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
byte bt_One, bt_Two; //定义两个 byte 变量
if (byte.TryParse(textBox1.Text, out bt_One) && byte.TryParse(textBox2.Text, out bt_Two)) //为两个 byte变量赋值
{
try
{
checked { bt_One += bt_Two; } //使用 checked 关键字判断是否溢出
textBox3.Text = bt_One.ToString(); //输出 相加后的结果
}
catch (OverflowException ex)
{
MessageBox.Show(ex.Message, "出错!");
}
}
else
{
MessageBox.Show("请输入 255 以内的数字!");
}
}
private void Form1_Shown(object sender, EventArgs e)
{
this.Text = "使用 checked 关键字处理 溢出 错误信息";
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Example22
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
byte bt_One, bt_Two; //定义两个 byte 变量
if (byte.TryParse(textBox1.Text, out bt_One) && byte.TryParse(textBox2.Text, out bt_Two)) //为两个 byte变量赋值
{
try
{
checked { bt_One += bt_Two; } //使用 checked 关键字判断是否溢出
textBox3.Text = bt_One.ToString(); //输出 相加后的结果
}
catch (OverflowException ex)
{
MessageBox.Show(ex.Message, "出错!");
}
}
else
{
MessageBox.Show("请输入 255 以内的数字!");
}
}
private void Form1_Shown(object sender, EventArgs e)
{
this.Text = "使用 checked 关键字处理 溢出 错误信息";
}
}
}
相关文章推荐
- 使用checked关键字处理“溢出”错误
- C#使用checked关键字处理"溢出"错误
- 使用checked关键字处理“溢出”错误
- C#使用checked关键字处理"溢出"错误
- 使用storm处理消息队列中的日志信息遇见的错误
- PHP 错误与异常 笔记与总结(15 )使用观察者模式处理异常信息
- java中三种常见内存溢出错误的处理方法
- 于仕琪老师《OpenCV入门教程》中某一程序在我电脑VS2008,opencv2.3.1上运行错误,“未使用调试信息生成二进制文件”,留待解决,
- 书羊农历控件使用步骤及处理错误:引发了“System.Windows.Forms.AxHost.InvalidActiveXStateException”类型的异常
- 在处理向该请求提供服务所需的配置文件时出错。请检查下面的特定错误详细信息并适当地修改配置文件。
- 使用memcache处理Session信息
- PHP自定义错误处理器处理出错信息
- valgrind 的使用及错误信息分析
- SqlServer 2012 THROW 及其他异常错误信息捕获处理
- yii 用户提示信息,错误提示信息的处理方法
- 由于内部错误,服务器无法处理该请求。有关该错误的详细信息,请打开服务器上的 IncludeExceptionDetailInFaults (从 ServiceBehaviorAttribute 或从 <serviceDebug> 配置行为)以便将异常信息发送回客户端,
- Atitit. null错误的设计 使用Optional来处理null
- JQuery上传插件Uploadify使用详解及错误处理
- 阿里云企业邮箱使用nodemailer,使用nodemailer发送错误信息
- 异常信息:由于内部错误,服务器无法处理该请求。有关该错误的详细信息,请打开服务器上的 IncludeExceptionDetailInFaults