Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Why can't you modify your static method to return an exception object and throw later. For example</p> <pre><code>// Do something ... // Found error condition, need to throw an exception if (error condition) { throw LogAndThrow.Message("Message goes here"); } </code></pre> <p>Edit: AFAIK, there no way to modify stack trace. There are ways to preserve original stack trace while re throwing exceptions - see this <a href="http://weblogs.asp.net/fmarguerie/archive/2008/01/02/rethrowing-exceptions-and-preserving-the-full-call-stack-trace.aspx" rel="nofollow noreferrer">article</a> for it.</p> <p><strong>Another Edit</strong>:</p> <p>Just thought that I will put some additional info &amp; links. Basically, CLR builds the stack trace in the exception object only when exception is thrown. This has been mentioned at <a href="http://msdn.microsoft.com/en-us/library/system.exception.stacktrace.aspx" rel="nofollow noreferrer">MSDN</a> - quote from MSDN:</p> <blockquote> <p>The common language runtime (CLR) updates the stack trace whenever an exception is thrown in application code (by using the throw keyword). If the exception was rethrown in a method that is different than the method where it was originally thrown, the stack trace contains both the location in the method where the exception was originally thrown, and the location in the method where the exception was rethrown. If the exception is thrown, and later rethrown, in the same method, the stack trace only contains the location where the exception was rethrown and does not include the location where the exception was originally thrown</p> </blockquote> <p>This is also mentioned <a href="http://msdn.microsoft.com/en-us/magazine/cc793966.aspx" rel="nofollow noreferrer">here</a> (where author mentions that CLR will do a stack walk when it encounters the exception in managed code). </p> <p>On somewhat related note (but a bit off-topic), see <a href="http://blogs.msdn.com/b/rmbyers/archive/2010/06/16/3453411.aspx" rel="nofollow noreferrer">this excellent article</a> (with sample code) where author constructs the alternate stack trace information (basically, he looks up debug information from non-standard location).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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