Both Java and C#, and probably many other languages too, have a predefined exception class that is thrown when a null parameter is used where it should not. Is there anything similar in C++? If not, is there another predefined exception I can use or should I define my own one?
Both Java and C#, and probably many other languages too, have a predefined exception
Share
Dereferencing a NULL pointer is undefined behaviour in C++ – which means the code can appear to work. An exception isn’t guaranteed to be thrown. You can use the
std::invalid_argumentexception (provide a meaningful value to it –
"p is NULL"), but you’ll have to do the check yourself.