The code looks good, the only problem I can imagine, maybe with execution, since the exception is considered not very efficient. If so, you can change the code to:
void DoTheJob(Logger& log) { Res1HolderNoThrow r1(); if( r1 ) { Res2HolderNoThrow r2(); if( r2 ) DoTheJobQuicklyAndEasily(log, r1, r2); else { log.log("Can't obtain resource 2, that'll slowdown us a bit"); DoTheJobWithModerateSuffering(log, r1); } } else { log.log("Can't obtain resource 1, using fallback"); DoTheJobTheSlowAndPainfulWay(log); } }
You will need another RAII object that does not throw an exception, but has a state and returns it in operator bool () or somewhere else. But your code looks less error prone, and I would prefer to use it if you don't have a performance problem or you need to avoid exceptions.
Slava
source share