カスタム例外クラスに対するすべての例外を処理したいと考えています。try ブロックでカスタム例外を発生させたくありません。すべての例外がカスタム例外クラスによってキャッチされるようにしたいのです。
私はこれをしたくありません:
private static void Main(string[] args)
{
try
{
Console.WriteLine("Exception");
throw new CustomException("Hello World");
}
catch (CustomException ex)
{
Console.WriteLine(ex.Message);
}
Console.ReadLine();
}
これ欲しい:
private static void Main(string[] args)
{
try
{
Console.WriteLine("Exception");
throw new Exception("Hello World");
}
catch (CustomException ex)
{
Console.WriteLine(ex.Message);
}
Console.ReadLine();
}
public class CustomException : Exception
{
public CustomException()
{
}
public CustomException(string message) : base(message)
{
}
public CustomException(string message, Exception innerException)
: base(message, innerException)
{
}
protected CustomException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
あなたが私の質問を理解してくれることを願っています。