助けてくれてありがとう。
除数が 1 の場合、このコードは期待どおりの結果を生成しません。ExceptOne の基本クラスが呼び出されず、ExceptOne のハイパーリンクが表示されません。何が足りないの?!
コンソール出力は次のとおりです。
除数を入力してください
1
WriteLine exception 1...
WriteLine exception 2...
base ctor2
http : // exc2.com
Writeline in finally
class Program
{
static void Main(string[] args)
{
try
{
byte y = 0;
byte x = 10;
Console.WriteLine("enter a divisor");
string s = (Console.ReadLine());
y = Convert.ToByte(s);
if (y == 1) throw new ExceptOne();
Console.WriteLine("result is {0}", x / y); ;
}
catch (System.DivideByZeroException e)
{
Console.WriteLine("exception occured {0}...", e.Message);
}
catch (ExceptOne p)
{
Console.WriteLine(p.Message +"\n"+ p.HelpLink);
}
catch (System.Exception r)
{
Console.WriteLine(r.Message + "\n" + r.HelpLink);
}
finally
{
Console.WriteLine("Writeline in finally ");
Console.ReadLine();
}
}
}
public class ExceptOne : System.Exception
{
public ExceptOne()
: base("base ctor 1 ")
{
this.HelpLink = "http://exc1.com";
Console.WriteLine("WriteLine exception 1...");
throw new Exception2();
}
}
public class Exception2 : System.Exception
{
public Exception2()
: base("base ctor2 ")
{
Console.WriteLine("WriteLine exception 2...");
this.HelpLink = "http://exc2.com";
}
}