(исходное содержание отредактировано, потому что я обнаружил, что оно не имеет значения)
В моем приложении есть универсальный HTTP-клиент RESTful, который переносит операции в
делегирует и проходит мимо моего метода WrapOperation (как показано ниже).
Однако, когда возбуждаются исключения, трассировка стека содержит только одну запись:
at MyProject.Client.RestClient.WrapOperation[T](String method, String path, Object requestObject, RestOperation`1 action) in D:\{fileName}\RestClient.cs:line 196
Я сократил код проблемы до следующего:
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 );
}
}
Когда выдается исключение «трассировка стека 6», при перехвате перехвата (WebException Wex) трассировка стека Wex содержит только одну запись.
Почему это?