RAII is a design pattern implemented by C++ programming language. Under it, resources are represented by objects, and are acquired on initialization and released on destruction. The last is one of the most useful property and that is not present in languages like Java. In this pattern, an object is destroyed whenever it goes out of scope or an exception in thrown.
The capability of recovering from exception is particularly useful when the resource is shared, for example lock. If the destructor was not called, then a deadlock could occur. If the resource was a dynamic allocated memory, we would have a memory leak.