(私はそれが無関係だった発見したので、初期コンテンツアウト、編集)、一般的な方法で消去.NET - 例外スタックトレースラインが
私のアプリケーションは 代表者に操作をラップし、ために過去である汎用RESTfulなHTTPクライアントを持っています私のWrapOperationメソッド(下記参照)。
例外が発生したときただし、スタックトレースにエントリが1つだけ含まれています:「スタックトレース6をテストする場合
private T WrapOperation<T>(String method, String path, Object requestObject, RestOperation<T> action) {
HttpWebRequest request;
RestTransaction txn = CreateRequest(method, path, requestObject, out request);
////////////////////////////
try {
throw new WebException("testing stack trace 6");
throw new Exception("testing stack trace 7");
using(HttpWebResponse response = (HttpWebResponse)request.GetResponse()) {
txn.GotResponse(response);
return action(txn, response);
}
} catch(WebException wex) {
// NOTE: When exceptions are caught, they're missing the first few entries of the stack trace
// And appear as though "WrapOperation[T]" (sic) is the entrypoint. Why is this?
if(wex.Response != null) {
HttpWebResponse response = (HttpWebResponse)wex.Response;
txn.GotResponse(wex, response);
CopyResponseToMemoryStream(response, txn).Dispose();
} else {
txn.GotResponse(wex);
}
// NOTE: However, when these RestExceptions are caught (by WrapOperation's caller), their stack trace is complete and shows the entire trace
throw new RestException("WebExeption during GetResponse.", txn, wex);
} catch(Exception ex) {
txn.GotResponse(ex);
// NOTE: However, when these RestExceptions are caught (by WrapOperation's caller), their stack trace is complete and shows the entire trace
throw new RestException("Non-WebException during GetResponse.", txn, ex);
}
}
:
at MyProject.Client.RestClient.WrapOperation[T](String method, String path, Object requestObject, RestOperation`1 action) in D:\{fileName}\RestClient.cs:line 196
を私はちょうどこの問題のコードを削減しました例外がスローされます。catch(WebException wex)によってキャッチされると、wexのスタックトレースには1つのエントリしか含まれません。
これはなぜですか?
例外コードは実際にどのように見えますか?例外をチェーンの下に渡すために 'throw ex'または単に' throw'していますか? – asawyer
欠落している中間メソッドのコードを投稿して推測しにくいようにしました。ここに少なくとも2つの場合があります。タスクによって実行されるメソッドのみが表示され、例外トレースはスレッドベースです。また、ジッタオプティマイザは小さなメソッドのインラインコードを生成するので、それらを見ることはできません。例外はスタックフレームベースです。 [MethodImpl]を使用して最適化を抑制します。 –
スレッドのエントリポイントはどのような方法ですか?それは
DoAsync(Action)
ですか?非同期タスクを作成、起動、実行するコードを表示してください。 –