2009年12月24日木曜日

カスタム例外を定義してthorw文を使用して例外の原因の詳細情報を表示してみる。

using System;


// 例外クラスを定義
class CustomException:Exception
{
    public CustomException(string message):base(message)
    {
    }
}
class MainClass
{
    static void Main()
    {
        try
        {
            // 例外をthrow
            throw new CustomException("例外をthrow");
        }
        catch (CustomException error)
        {
            // 出力値:例外をthrow
            Console.WriteLine(error.Message);
        }
        finally
        {
            Console.WriteLine("終了");
        }
    }
}

0 コメント:

コメントを投稿