using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class userException:Exception{
public userException() { }
public userException(string ms) : base(ms) { }
public userException(string ms, Exception inner) : base(ms, inner) { }
}
class Num {
private int number;
public void setNum(int number){
if(number<0||number>9){
throw (new userException("你输入的是0~9以外的字母或符号~~"));
}
if(number.GetType().ToString()!="System.Int32"){
throw (new userException("你输入的不是数字~~"));
}
this.number = number;
}
}
class Program
{
static void Main(string[] args)
{
Num num = new Num();
int m;
Console.Write("请输入一个0~9之间的数字:");
m = Convert.ToInt16(Console.ReadLine());
try
{
num.setNum(m);
}
catch (Exception e)
{
Console.WriteLine("产生异常:{0}", e.Message);
}
Console.ReadKey();
}
}
}