1)テスト例外を作成しました。私は私のクラスにベース例外からキャストすることはできませんしかしC#例外の間にキャストされるユーザー定義の例外?
catch (Exception e)
{
TestException myOwnException = new TestException(e);
myOwnException.Info = "test";
LogError(myOwnException);
}
:どこかに私はこのような何かを得たウェブサイト内の関数で
public class TestException : Exception
{
string info;
public string Info { get { return info; } set { info = value; } }
public TestException() { }
public TestException(string message) : base(message) { }
public TestException(string message, Exception inner) : base(message, inner) { }
protected TestException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context)
: base(info, context) { }
}
2)。 logErrorは、TestExceptionを予期します。
私はExceptionクラス内でこれを作成してみました。
public static implicit operator TestException(Exception e)
{
return new TestException(e);
}
しかし、私はちょうど得続ける(私はTestException myOwnException =電子を書くことができます):基底クラスへまたはから ユーザ定義の変換はありません許可されます。
catchステートメントから例外を私のTestExceptionクラスにキャストする方法はありますか? (私もTestException test =(TestException)eを試みましたが、エラーを返すだけです。
LogErrorの定義とは – sukru