嗯...寫一個可能沒有時間,不過提供一些思路:1.寫一個類,繼承自Exception或者ApplicationException(微軟建議繼承后者):public UserException : System.ApplicationException
{}2.
try
{

catch(Exception ex)

   //對異常進行處理;   throw new UserException(); //拋出自定義的異常;
}

解决方案 »

  1.   

    上面寫錯了public class UserException : System.ApplicationException
    {}
      

  2.   

    throw new “what you want other see”;
      

  3.   

    using System;
    class ExceptionDemo
    {
    static void Main()
    {
    int num;
    try
    {
    num = Convert.ToInt32(Console.ReadLine());
    if(num < 0)
    throw new MyException(2000, "小于零");
    }
    catch(MyException err)
    {
    Console.WriteLine(err.Number);
    Console.WriteLine(err.Message);
    }
    }
    }
    class MyException:System.ApplicationException
    {
    private uint errorNumber;
    public MyException():base("myException"){}
    public MyException(uint number, string message):base(message)
    {
    this.errorNumber = number;
    }
    public uint Number
    {
    get {return this.errorNumber;}
    }
    }