主题:请指教:怎样创建C#自定义异常?谢谢.
我想这样:当把outtnum用循环赋值给getnum的时候就引发自定义异常抱错.但不知道具体应该怎么做.书上写的非常冷统.连个具体例子都没有.看的我简直郁闷死了!!!!
以下运行以后没有显示出相关错误提示,请问是什么原因?应该怎么改正.谢谢....
using System;
using System.Collections.Generic;
using System.Text;
namespace Exception
{
class Program
{
class MyException : ApplicationException
{
public MyException(string message): base(message)
{
}
}
static void Main(string[] args)
{
int[] getnum = new int[3];
int[] outnum ={ 1, 2, 3, 4 };
try
{
for (int i = 0; i < outnum.Length; i++)
{
getnum[i] = outnum[i];
}
}
catch (MyException ce)
{
Console.WriteLine(ce.Message);
}
}
}
}
以下运行以后没有显示出相关错误提示,请问是什么原因?应该怎么改正.谢谢....
using System;
using System.Collections.Generic;
using System.Text;
namespace Exception
{
class Program
{
class MyException : ApplicationException
{
public MyException(string message): base(message)
{
}
}
static void Main(string[] args)
{
int[] getnum = new int[3];
int[] outnum ={ 1, 2, 3, 4 };
try
{
for (int i = 0; i < outnum.Length; i++)
{
getnum[i] = outnum[i];
}
}
catch (MyException ce)
{
Console.WriteLine(ce.Message);
}
}
}
}