c# - WPF unhandled exception handler and preserve call stack -
i have wpf application , need write mini dump file whenever application encounters unhandled exception debugging. however, every time exception handler called, stack unwound handler , there no useful state can use in dump file.
i tried subscribe both of these , stack unwound both of them:
application.current.dispatcherunhandledexception appdomain.currentdomain.unhandledexception i tried same console app , stack not unwound wpf-related. exception , handlers both happen in main thread.
here 2 code samples can see easily. set breakpoints in each handler , observe call stack when breakpoints hit.
console app:
class program { static void main(string[] args) { appdomain.currentdomain.unhandledexception += new unhandledexceptioneventhandler(currentdomain_unhandledexception); int foo = 5; ++foo; throw new applicationexception("blah"); ++foo; } static void currentdomain_unhandledexception(object sender, unhandledexceptioneventargs e) { console.writeline("blah"); } } wpf app:
public partial class app : application { protected override void onstartup(startupeventargs e) { application.current.dispatcherunhandledexception += new system.windows.threading.dispatcherunhandledexceptioneventhandler(current_dispatcherunhandledexception); appdomain.currentdomain.unhandledexception += new unhandledexceptioneventhandler(currentdomain_unhandledexception); int foo = 5; ++foo; throw new applicationexception("blah"); ++foo; base.onstartup(e); } void currentdomain_unhandledexception(object sender, unhandledexceptioneventargs e) { } void current_dispatcherunhandledexception(object sender, system.windows.threading.dispatcherunhandledexceptioneventargs e) { e.handled = false; } }
Comments
Post a Comment