haihongyuan.com
海量文库 文档专家
全站搜索:
您现在的位置:首页 > 小学教育 > 学科竞赛学科竞赛

整除异常

发布时间:2013-12-13 13:32:10  

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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
class MyException : Exception
{
public MyException() { }
public MyException(string ms) : base(ms) { }
public MyException(string ms, Exception inner) : base(ms, inner) { }
}
class A
{
double a;
double b;
public double st(double a, double b)
{



if (a < -1000 || a > 1000)
{
throw (new MyException("输入的数值不符合要求,范围应在-1000到1000之间"));
}
if (b < -1000 || b > 1000)
{
throw (new MyException("输入的数值不符合要求,范围应在-1000到1000之间"));

}
if (b == 0)
{
throw (new MyException("除数不能能为零"));
}
return a / b;
if ((a > 'a' && a < 'z') || (a > 'A' && a < 'Z'))
{

throw (new MyException("输入的不是数值"));
}
this.a = a;
this.b = b;

}
}
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
try
{
A c = new A();
MessageBox.Show("结果为:" + c.st(double.Parse(textBox1.Text), double.Parse(textBox2.Text)).ToString());
}
catch (MyException ex)
{
label3.Text = "产生异常" + ex.Message;
}
catch (Exception es)
{
label3.Text = "产生异常" + es.Message;
}
finally
{
MessageBox.Show("程序正确结束");
Close();
}
}

private void label3_Click(object sender, EventArgs e)
{

}


}
}

网站首页网站地图 站长统计
All rights reserved Powered by 海文库
copyright ©right 2010-2011。
文档资料库内容来自网络,如有侵犯请联系客服。zhit326@126.com