I used to use initialization list
through Constructor and everything went well. But now I need some exception handling
in my class.
So here is some sample code:
1- Without exception handling
class CVector{
public:
CVector(const int);
protected:
int* pInt;
int size;
};
CVector::CVector(const int sz) :
pInt{ new int[sz]}, size{ sz}{
}
The constructor above doesn't check whether an invalid sized is passed, or new
failed...
Now I edited the constructor to handle exceptions:
2- With exception handling:
CVector::CVector(const int sz){
size = sz;
if(size <=0 )
throw; // some exception object
pInt = new int[sz];
if(nullptr == pInt)
throw; // some memory exception
}
- The problem now: Are they exclusive? - I mean How to mix exception handling with initialization-list through Constructor?