c# - How to catch and log exception inside Using statement without using try-catch? -
as know using statement has built in implementation of dispose() , try-catch. want know few things
is possible log exception inside using statement without using try-catch block , either inside or outside statement. if not, why built in statement.
nested or overuse of try-catch not preferred, why such model preferred use.
using (some_resource) { try { } catch { } { //my exception logging mechanism } }
will become
try { try { } catch { } { //my exception logging mechanism } } catch { } { //some_resource.dispose() }
a using
statement involves try
/finally
; there no catch
. frankly, concern overkill; multiply-nested , complex try
/catch
/finally
"undesirable" because:
- it makes code hard read
- and harder right (most people wrong, alas)
- it misused
- it suggests method doing much
with using
, isn't issue; makes intent clean, without adding complexity or concern.
i use:
using (some_resource) { try { // code } catch (exception ex) { logit(ex); throw; } }
Comments
Post a Comment