Unlock mutex on exception

Viewed 3977
mutex.lock();
try
{
    foo(); // can throw exception
}
catch (...)
{
    mutex.unlock();
    throw;
}
mutex.unlock();

To guaranty the unlock i must call mutex.unlock() in catch block and in normal case. Is there any option to avoid duplication?

Thank You

1 Answers
Related