Resource Acquisition is Initialisation or shortly RAII is a term closely connected with exception handling and automatic garbage collection(speaking loosely). RAII is defined as the technique of performing all necessary resource initialisation work right within the body of the constructor itself, and correspondingly doing all the deallocation within the destructor. Since during exception handling destructors of all the classes whose constructors have been successfully invoked, are called therefore all the local objects previously allocated are automatically deallocated without explicitly calling their destructors.the following example explains the RAII technique:class X{ int *r; public: X(){cout<<"X is created"; r=new int[10]; } ~X(){cout<<"X is destroyed"; delete [] r; }};class Y{ public: Y(){ X x; throw 44; } ~Y(){cout<<"Y is destroyed";}};Now since Y throws an exception right in its constructor therefore its destructor won't get called becuse the constructor was not invoked successfully. But the destructor of the class X will definitely be called and therefore the array 'r' will be deallocated. So we didn't have to care about resource deallocation at the time exceptions are raised.
If you have the better answer, then send it to us. We will display your answer after the approval.