18.10 EXCEPTIONS IN CONSTRUCTORS AND DESTRUCTORS

Under normal circumstances, in simple programs, one does not expect an exception to occur. It has to be understood that the ensuing discussion is basically for advanced programmers. The most typical task where this discussion is most relevant is the development of libraries. When someone is writing a library function, he is aware of possible error. But he has no clue about what the user of library wants to do in this circumstance.

Most natural cause of error with constructor is when we are trying to create an object using new operator. Sometimes available memory may not be sufficient. The natural safeguard provided by the system is that it returns “null”. However, programmers hate to check every ...

Get Object Oriented Programming with C++, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.