Create c# exception and not throw it -


is there way better i'll have written below exception set when thrown?

try { throw new exception("blah"); } catch (exception exe) { assert.notnull(exe.stacktrace); dosomework(exe); // throw; } 

the short answer : no.

the system.exception properties filled in when thrown:

by default, stack trace captured before exception object thrown. use environment.stacktrace stack trace information when no exception being thrown.

so if need exception object in state after being thrown have no other way throw , catch it.

still not drop off main question: need exception object?

if you've got method has system.exception input parameter , need stacktrace inside, think of these possible solutions:

  1. method overload optional stacktrace input parameter.
  2. a successor of system.exception hiding stacktrace property memorizes stacktrace when object created not thrown.
  3. as last resort make extension method system.exception class "populates" instance of system.exception:

    private void mycode() {     exception exe = new exception("blah");     exe.populate();     dosomework(exe); }   public static void populate(this system.exception source) {     try     {         throw source;     }     catch     {     } } 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -