How can we do exception handling for declaring object of the class in C++?
Exception Handling
Collapse
X
-
The best check after declaring a new object is to check if it has been allocated the memory or not :
Class * obj = new Class;
if ( !obj)
{
//raise error...
}
Also it would be a good idea to use memset on the newly declared object so that it doesnt carry a garbage value...
memset ( obj, '\0', sizeof(obj) ;
Comment