using System;
class MainClass
{
static void ExceptionMethod()
{
try
{
int a = 0;
a /= a;
}
catch (Exception)
{
Console.WriteLine
("ゼロ除算の例外をcatch¥nそしてthrow");
throw new DivideByZeroException();
}
}
static void Main()
{
try
{
ExceptionMethod();
}
catch (Exception error)
{
Console.WriteLine
("次はすべての例外をcatch");
// 例外の原因の詳細情報を表示
Console.WriteLine(error.Message);
}
finally
{
Console.WriteLine("終了");
}
}
}
0 コメント:
コメントを投稿