Reporting an Error During Object’s Construction

Constructors have no return value (not even void). Therefore, you have to use alternative techniques of reporting errors during object’s construction. There are three common techniques of reporting such errors.

The first technique uses C-style error handling: when an error occurs during construction, the constructor assigns an error value to a global variable, which is later examined. Although this is the least preferable technique, it can be useful when combining legacy code written in C with new C++ code.

 int errcode = OK;   // global flagDate::Date(const char *datestr){  if (isValid(datestr) == flase)    errcode = EINVALIDDATE;//

Share the Post:
Share on facebook
Share on twitter
Share on linkedin


Recent Articles: