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
Post a Comment