Getting at the source of a nested exception (TypeInitializationException)



When an exception is thrown in a static initializer, it is caught
and wrapped in a TypeInitializationException.

Presently, I track these cases down by catching and rethrowing
the TypeInitializationException; then the debugger gets positioned
where I can examine the exception and peel it to the innermost
exception (often nested in other TypeInitializationExceptions),
then I can set a breakpoint in the offending static initializer and
initialize it.

I just wonder if there is an easier way... can I make the debugger
act as if the original exception was never caught, and take me
straight to the bad line of code?

I'm using VS2005 pro, C#.

Ole N.


.



Relevant Pages

  • Re: Static initilizer failed to execute?
    ... John C. Bollinger wrote: ... >> Here is the static initializer code. ... >>} catch (Exception e) ... In this particular case, crashing is exactly what I would expect, but thanks ...
    (comp.lang.java.programmer)
  • Re: typeinitializationexception in module
    ... Well if your constructor is calling lots of other things, ... typeInitializationException with the main exception set as inner exception. ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: static classloading issue...
    ... We are facing a hard-to-debug problem i our Weblogic server. ... Here is the exception: ... Sounds like an exception throws in static initializer. ...
    (comp.lang.java.programmer)
  • Static constructor exception vanishes
    ... Under the full .NET framework: if an exception is thrown from within a ... TypeInitializationException and then throws the ... Instead a TypeLoadException is thrown, ...
    (microsoft.public.dotnet.framework.compactframework)