【发布时间】:2012-05-30 02:40:24
【问题描述】:
这种模式我已经见过几次了:
bool success = false;
try
{
DoSomething();
success = true;
}
finally
{
if (!success)
Rollback();
}
我一直在想:为什么这比使用 catch 进行回滚更好?
try
{
DoSomething();
}
catch
{
Rollback();
throw;
}
确保更改在失败时回滚的两种方法有什么区别?
【问题讨论】:
标签: c# transactions try-catch try-finally