Webアプリケーションで例外を処理するための次のコードがあります。
application.Response.Clear();
application.Response.Status = Constants.HttpServerError;
application.Response.TrySkipIisCustomErrors = true;
LogApplicationException(application.Response, exception);
try
{
WriteViewResponse(exception);
}
// now we're in trouble. lets be as graceful as possible.
catch (Exception exceptionWritingView)
{
// Exception wrapper = ??
WriteGracefulResponse(exceptionWritingView);
}
finally
{
application.Server.ClearError();
}
ここでの問題は、応答をとしてレンダリングしようとしているときに例外が発生した場合、元の例外を(とにかく)ViewResult「抑制」し、エラーがスローされた原因を表示するだけであるということです。ViewViewResult
exception両方を取り、両方でexceptionWritingView1つの例外を作成exceptionWritingViewし、上部に配置します。
これは:
exceptionWritingView
-> inner exceptions of exceptionWritingView
-> original exception that raised the unhandled exception handler
-> its inner exceptions
しかし、オブジェクトにInnerExceptionプロパティを設定することはできません。exceptionでは、どうすればこれを達成できますか?
「最高の」状態で、Exceptionを使用して新しいものを作成することはできますが、プラスnew Exception(exceptionWritingView.Message, exception)の一部を失うことになり、持っていた可能性のあるものを失うことになります。StackTraceInnerExceptionexceptionWritingView
ここでの唯一の方法は反射ですか?振り返ってそれをするのはそれほど恐ろしいことでしょうか?