c# - using & try/catch nesting -


this question more of right way something...

the question...is there proper nesting order between using block , try/catch?

is ok nest entire using statement inside of try/catch , maintain benefits of using block? (or exception cause closing portion of using statement thrown out window)

or should nest try/catch inside using statements , surround statements database access?

is...

try {      using( tsmtcowebentities db = new tsmtcowebentities() ) {           violationlist = ( in db.drivertrafficviolationdetails                             a.drivertrafficviolation.driverapplicationid == driverappid                             orderby a.dateofoccurance descending                             select ).tolist<drivertrafficviolationdetail>();           generalviolation = ( in db.drivertrafficviolations                                a.driverapplicationid == driverappid                                select ).firstordefault();      } } catch { } 

less/more correct than...

using( tsmtcowebentities db = new tsmtcowebentities() ) {      try {           violationlist = ( in db.drivertrafficviolationdetails                             a.drivertrafficviolation.driverapplicationid == driverappid                             orderby a.dateofoccurance descending                             select ).tolist<drivertrafficviolationdetail>();           generalviolation = ( in db.drivertrafficviolations                                a.driverapplicationid == driverappid                                select ).firstordefault();      } catch { } } 

the later better: it avoid masking exceptions thrown dy dispose. see article.


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -