devxlogo

Reporting an Error During Object’s Construction

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;//

See also  Professionalism Starts in Your Inbox: Keys to Presenting Your Best Self in Email
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist