visual studio 2010 - Getting an Unhandled Exception in VS2010 debugger even though the exception IS handled -
i have issue vs2010 debugger stops unhandled exception. however, exception handled. in fact, if put code in catch block, i'll hit when press f5. in debug -> exceptions, not have "thrown" checkbox checked, imo there absolutely no reason unhandled exception dialog pop up...
i can't post exact code, work on sample soon. basic idea behind offending code section have thread talks hardware, , if have error talking it, throw hardwareexception. thread launched begininvoke, , exception caught in callback handler when call endinvoke.
when exception thrown in debugger, messagebox says 'hardwareexception not handled user code". is!!!
edit -- well, driving me crazy. i've got sample code representative of code have in application, , looks this:
using system; using system.collections.generic; using system.linq; using system.text; using system.runtime.remoting.messaging; using system.threading; namespace consoleapplication1 { public class hardwareexception : applicationexception { public hardwareexception( string message) : base(message) {} } class program { delegate void hardwaretestdelegate(); static void main(string[] args) { hardwaretestdelegate d = new hardwaretestdelegate( hardwaretestthread); d.begininvoke( hardwaretestcomplete, null); while( true); } static void hardwaretestthread() { throw new hardwareexception( "this test"); } static void hardwaretestcomplete( iasyncresult iar) { try { asyncresult ar = (asyncresult)iar; hardwaretestdelegate caller = (hardwaretestdelegate)ar.asyncdelegate; caller.endinvoke( iar); } catch( exception ex) { console.writeline( "should see line without getting unhandled exception message in ide"); } } } } i throw hardwareexception thread, , handle exception when endinvoke called. guess murphy right, because when run sample code, expect -- i.e. no unhandled exception error message pops in ide!
here response microsoft, case 111053102422121. allen weng writes following:
analysis:
for information, clr re-throw exception inside callback when call endinvoke(). below simplified version of endinvoke():
public object endinvoke(iasyncresult asyncresult) { using (new multithreadsafecallscope()) { threadmethodentry entry = asyncresult threadmethodentry; ............ if (entry.exception != null) { throw entry.exception; } } } the exception handled in call function or in asynchronous method if exception handler provided. how works without debugger attached.
when run in vs.net, debugger seems checking presence of exception handler in asynchronous method. if there no such handler, debugger think exception not handled , pop error message notifying of this.
suggestion:
the application should work expected when run stand alone. if error message annoying in debugging you, can disable unchecking “user unhandled” “common language runtime exceptions”in exception dialog box (debug|exceptions or press ctrl+atl+e). or can add try/catch in asynchronous method. in latter case, exception set null , won’t re-thrown in endinvoke().
Comments
Post a Comment