This is a discussion on Re: C++ exceptions - KDE ; Inline. On Monday 05 December 2005 07: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 ...
Inline.
On Monday 05 December 2005 07: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();
> }
error_t writeFile() {
error_t err;
if( (err = writeHeader()) || //this stops processing on the first error
(err = writeContent()) ||
(err = writeFooter() ) )
return err;
return 0;
}
> //...
>
> try {
> writeFile();
> } catch (DiskFullException e) {
> error("disk is full");
> }
if( writeFile() == EDiskFull )
error("disk is full");
Having said this, exceptions are very useful in situations where the problem
gets a little deeper or you have a more than a few levels of indirection
present but as Thiago pointed out earlier they come with a price so they
should be used with care.
>
> > I have no idea about java.
>
> Gee, that's surprising to hear.
Please don't turn an already-religious topic into a flame war.
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<