c# - ApplicationException not being thrown to catch block properly -


i having issue override onvalidate method of linq sql class. have written business rules , well, when go catch exception in call repository, application treating exception unhandled.

in linq sql partial class have following:

    partial void onvalidate(changeaction action)     {         if (!isvalid)             //application halting here before catch block code reached             throw new applicationexception("invalid note data recieved!  correct following issues , try again:");         //updatetimestamp();     } 

the isvalid set of checks on linq sql class properties.

in form have button click event calls submitchanges method on repository class. have wrapped in try/catch block exception not bubble catch instead errors @ throw new applicationexception() block in partial class.

here code around button: (repository injected implementation of irepository).

    private void submitbutton_click(object sender, eventargs e)     {         try         {             if (isnewnote)             {                 //currentnote instance of linq sql class.                 this.repository.insertnote(currentnote);             }             this.repository.save();         }         catch (applicationexception ex)         {             messagebox.show(string.format("{0}" + environment.newline + "{1}", ex.message, this.currentnote.getruleviolations().firstordefault().errormessage));         }     } 

and context here insertnote() , save() methods on repository implementation (nothing special, basic linq sql calls).

    public void insertnote(unvoucheredinventorynote note)     {         _db.unvoucheredinventorynotes.insertonsubmit(note);     }      public void save()     {          _db.submitchanges();     } 

i have tried catching , re-throwing exception in save() method, still fails , points throw line in onvalidate method.

what cause exception halt @ line , not bubble catch block in presentation layer?

thanks comments reed copsey , astander, figured out. debugger set break on user unhandled exceptions applicationexception , system.exception.

the reason did not catch earlier because thought "handling" them in catch block in way override first chance functionality, apparently not case.

turning off break on exception functionality allowed exception bubble wanted it.

for brevity here steps performed this:

  1. go debug menu in vs
  2. click on 'exceptions...'
  3. expand 'common language runtime (clr) exceptions
  4. uncheck type of exception do not want caught first chance debugger
  5. click ok

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -