B
Brian Folke Seaberg
I was recently browsing a couple of C++ books at the local bookstore.
One book called throwing exceptions from constructors a "dubious practice."
Another book recommended not throwing exceptions from constructors due to the
fact that the destructor for the object being constructed will not be executed
and that as a result any resources allocated by the constructor prior to
throwing the exception will not be deallocated if the deallocation is dependent
upon the execution of the destructor. The author suggests setting a status
indicator and requiring clients of the class and even member functions of the
class to examine that status indicator prior to accessing members rather than
signaling constructor failure via the exception mechanism.
My initial reaction to the first book was that the practice is not dubious but
is in fact a technique that is accepted by the C++ community at large
(including the originator of the language.)
My initial reaction to the second book was that if programmers understand the
mechanics of object construction and destruction and knew of exception safe
programming techniques such as those taught by Meyers, Sutter and others that
it becomes a perfectly safe method for handling constructor failure.
Dangerous in the hands of the unknowing...maybe.
Dubious...I don't know about that.
Are these authors in the minority?
If one of these guys interviewed me I would not be sure I wanted to work for
them. Of course since these guys are being paid to author C++ books and I am
not I will assume they are the more knowledgeable C++ programmers
I am sure all techniques for handling failure have appropriate and
inappropriate contexts in which they can be applied.
I am curious to know what the members of this newsgroup think.
===============
Brian Folke Seaberg
===============
"A noble spirit embiggens the smallest man" -- Jebediah Springfield
One book called throwing exceptions from constructors a "dubious practice."
Another book recommended not throwing exceptions from constructors due to the
fact that the destructor for the object being constructed will not be executed
and that as a result any resources allocated by the constructor prior to
throwing the exception will not be deallocated if the deallocation is dependent
upon the execution of the destructor. The author suggests setting a status
indicator and requiring clients of the class and even member functions of the
class to examine that status indicator prior to accessing members rather than
signaling constructor failure via the exception mechanism.
My initial reaction to the first book was that the practice is not dubious but
is in fact a technique that is accepted by the C++ community at large
(including the originator of the language.)
My initial reaction to the second book was that if programmers understand the
mechanics of object construction and destruction and knew of exception safe
programming techniques such as those taught by Meyers, Sutter and others that
it becomes a perfectly safe method for handling constructor failure.
Dangerous in the hands of the unknowing...maybe.
Dubious...I don't know about that.
Are these authors in the minority?
If one of these guys interviewed me I would not be sure I wanted to work for
them. Of course since these guys are being paid to author C++ books and I am
not I will assume they are the more knowledgeable C++ programmers
I am sure all techniques for handling failure have appropriate and
inappropriate contexts in which they can be applied.
I am curious to know what the members of this newsgroup think.
===============
Brian Folke Seaberg
===============
"A noble spirit embiggens the smallest man" -- Jebediah Springfield