RAII Design Patterns and Alternatives

J

JohnQ

Scenario: A GUI program is developed such that the startup sequence is
controlled by the instantiation of a key object which instantiates other
objects etc. until it finally arrives at the point where it is waiting in
the message loop for messages to be put in its queue.

That is, unless something goes wrong during one of those object
instantiations in the program startup processing! Say somewhere in the
middle of all that startup processing, something does go wrong. Well, if the
objects were built with the RAII/exception architecture, the stack would
unwind back to the catch point. At which point, just maybe, an error would
be logged and the program would abort.

Or maybe, knowing that the OS is going to clean up resources for us when the
program aborts, maybe it is a lot simpler just to program the objects so
that they log and abort (sans exceptions) whenever they encounter error.

Whaddaya think?

John
 
P

Phlip

JohnQ said:
Or maybe, knowing that the OS is going to clean up resources for us when
the program aborts, maybe it is a lot simpler just to program the objects
so that they log and abort (sans exceptions) whenever they encounter
error.

Whaddaya think?

Write code ready to be refactored and upgraded. That means never rely on the
Memory Fairy today, if tomorrow a given method might move inside a loop, and
then cause a runaway leak.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top