It is possible that exceptions might raise in a constructor or destructors. If an exception is raised in a constructor, memory might be allocated to some data members and might not be allocated for others. This might lead to memory leakage problem as the program stops and the memory for data members stays alive in the RAM. Similarly, when an exception is raised in a destructor, memory might not be deallocated which may again lead to memory leakage problem. So, it is better to provide exception handling within the constructor and destructor to avoid such problems. Following program demonstrates handling exceptions in a constructor and destructor: #include<iostream> using namespace std; class Divide { private: int *x; int *y; public: Divide() { x = new int(); y = new int(); cout<<“Enter two numbers: “; cin>>*x>>*y; try { if(*y == 0) { throw *x; } } catch...
This website is made for my those friends who loves computer programming or want to learn hacking for educational purposes or either are interested in getting updated of new technology. For newbies it is a perfect website to get started.