using System;
class CustomException : Exception
{
// コンストラクタでMessageプロパティに文字列を設定する
public CustomException(string message)
: base(message)
{
}
}
class MainClass
{
static void Main()
{
try
{
// カスタム例外をスロー
throw new CustomException("例外をスロー");
}
catch (CustomException error)
{
// 出力値:例外をスロー
Console.WriteLine(error.Message);
}
finally
{
// 出力値:終了
Console.WriteLine("終了");
}
}
}
0 コメント:
コメントを投稿