c# - Try in finally block -
c# - Try in finally block -
try { operation1(); operation2(); ... } { seek { finalizer_operation1(); finalizer_operation2(); } { very_critical_finalizer_operation_which_should_occurs_at_the_end(); } }
is ok? have finalizer try/finally block (because finalizer_operationx() may throw , must ensure very_critical...() happens @ end.
quick googling try in block brings nil (will delete question if give me duplicate link), should work, unsure in design , possible problems it.
i not write code way. don't nesting try/catch/finally constructs. prefer 1 per method.
my preference wrap each of calls in own method.
try { operation1(); operation2(); ... } { cleanup(); } public void cleanup() { seek { finalizer_operation1(); finalizer_operation2(); } { very_critical_finalizer_operation_which_should_occurs_at_the_end(); } } c# try-finally
Comments
Post a Comment