恳请赐教如何建立一个标准的c#自定义异常?谢谢.....(忙活了2个小时终于搞定了!封贴
终于让我找到一篇资料.看了资料才明白怎么回事.终于做出来了!
哈哈,感谢上帝!
感谢大家!
下面是我做的:
using System;
public class MyException:Exception
{
public string s;
public MyException():base()
{
s=null;
}
public MyException(string message):base()
{
s=message.ToString();
}
public static void Test()
{
bool flag = false;
int[] num ={ 1, 2, 3, 4, 5, 6 };
int[] getnum = new int[5];
try{
for (int i = 0; i < num.Length; i++)
{
getnum[i] = num[i];
}
}
catch(Exception e){
flag =true;
}
if (flag == true)
{
throw new MyException("这样可不行啊大哥!数组越界了!!!!!");
}
}
public static void Main()
{
try
{
Test();
}
catch(MyException e)
{
Console.WriteLine(e.s);
}
}
}
[此贴子已经被作者于2007-10-21 0:43:36编辑过]