[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: C++ exceptions
From:       Tommi =?iso-8859-1?q?M=E4kitalo?= <tommi () tntnet ! org>
Date:       2005-12-05 13:50:45
Message-ID: 200512051450.45945.tommi () tntnet ! org
[Download RAW message or body]

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 <<
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic