From kde-devel Mon Dec 05 13:50:45 2005 From: Tommi =?iso-8859-1?q?M=E4kitalo?= Date: Mon, 05 Dec 2005 13:50:45 +0000 To: kde-devel Subject: Re: C++ exceptions Message-Id: <200512051450.45945.tommi () tntnet ! org> X-MARC-Message: https://marc.info/?l=kde-devel&m=113379073722458 Am Montag, 5. Dezember 2005 14:29 schrieb Michael Buesch: > On Monday 05 December 2005 14:02, Guillaume Laurent wrote: > > Michael Buesch wrote: > > > It is all about _coding_ in a clean way. > > > > Indeed. So show us how to rewrite the following in a clean way with > > return codes : > > > > void writeFile() { > > writeHeader(); > > writeContent(); > > writeFooter(); > > What if the exception raises in writeFooter()? Don't you want > to unwind writeContent() and writeHeader()? > Maybe not in this particular case, but _if_ you have to unwind it? > Insert try/catch blocks into writeFile()? Or how would you solve this? > This is a real question, no flamewar. > In my C++-servlet-engine tntnet I have a class tnt::savepoint, which is able to handle this. You can instantiate a tnt::savepoint on the stack, which stores the byte-position in my output. When done with my output, I tell savepoint to commit. If savepoint is destroyed without commit, it discards the content made after savepoint-instantiation. This works, because tntnet collect the output in a std::string. I need a system, which can be rolled back somehow. This is not a specific problem with exceptions. You have the same problem with returncodes. Exceptionhandling makes errorhandling easy and safe especially in deep call stacks (more than 1;-) ). Tommi >> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<