A hardware failure cannot lead to a C ++ exception. On some systems, hardware exceptions are a completely different mechanism than C ++ exceptions. In other cases, C ++ exceptions are built on top of the hardware exception mechanism. So this is not a question of general design.
If you want to restore, you need to be transactional - every state change must be completed before completion or canceled completely. RAII is part of this. As Chris Becke notes in another answer, there is more information than resource acquisition.
There is the idiom copy-modify-swap, which has used a lot for transactions, but it can be too hard if you are trying to adapt the working code to handle this "one million" case.
If you really need reliability, isolate the code in the process. If a hardware error kills the process, you can restart its watchdog timer. The OS will return the lost resources. Your code will only need to worry about a transactional state with a constant state, for example, in a file stored in files.
source share