Note that there are some explanatory texts on larger screens.

plurals
  1. PO.NET - Exception stack trace lines erased on generic methods
    text
    copied!<p>(Initial content edited out because I discovered it was irrelevant)</p> <p>My application has a general-purpose RESTful HTTP client which wraps operations in delegates and is past to my WrapOperation method (as seen below).</p> <p>However, when exceptions are raised the stack trace only contains one entry:</p> <pre><code>at MyProject.Client.RestClient.WrapOperation[T](String method, String path, Object requestObject, RestOperation`1 action) in D:\{fileName}\RestClient.cs:line 196 </code></pre> <p>I've reduced the problem code to just this:</p> <pre><code>private T WrapOperation&lt;T&gt;(String method, String path, Object requestObject, RestOperation&lt;T&gt; 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 ); } } </code></pre> <p>When the "testing stack trace 6" exception is thrown, when caught by the catch(WebException wex), wex's stack trace only contains one entry.</p> <p>Why is this?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload