Programming Topics + Overload Journal #29 - Dec 1998
Browse in : All > Topics > Programming
All > Journals > Overload > 29
Any of these categories - All of these categories

Note: when you create a new publication type, the articles module will automatically use the templates user-display-[publicationtype].xt and user-summary-[publicationtype].xt. If those templates do not exist when you try to preview or display a new article, you'll get this warning :-) Please place your own templates in themes/yourtheme/modules/articles . The templates will get the extension .xt there.

Title: Exception Errors

Author: Administrator

Date: 27 December 1999 17:23:23 +00:00 or Mon, 27 December 1999 17:23:23 +00:00

Summary: 

Body: 

Dear John, I just received Overload 28, and am as usual baffled by The Harpist. This time, however, I think it may be his or your fault as well as mine...

On P20 column 1, the Harpist begins a paragraph 'The last of these mechanisms', at which point one's eyes flick up to the paragraph above, to find a list - the last item is calling exit(). I think actually the Harpist means that returning an error code is not possible in destructors - but he definitely got me scratching my head.

In column 2 of P20 he declares a constructor like this

CanFail() : failed(true)
{
  failed = true;
}

Which doesn't strike me as very handy either. I suppose he meant

CanFail() : failed(true)
{
  failed = false;
}

but even this seems a perversely negative and unclear way of writing something like

bool builtFlag;

CanFail() : builtFlag(false)
{
  // body - maybe can exit here...
  builtFlag = true; 
  // successful construction
}

at which point built() becomes a straight accessor function rather than a strange little negator. Or have I missed the point entirely? I am a Delphi-head - there, I've admitted it. When Borland introduced exception handling into its Object Pascal implementation, the result was cleaner, more natural and safer code. Since Stroustrup introduced exceptions into C++, my impression is that resulting C++ code is usually a hideous, hard-to-read mess full of memory leaks. An impression strongly reinforced by the wrapped up function at the bottom of page 21 column 2.

The secret of good exception based code in Delphi is that you very, very rarely need to use the 'except' keyword (approximately analogous to C++'s 'catch') - see the excellent book 'Delphi Component Design' by Danny Thorpe for a wonderful discussion of how Delphi exceptions work.

What the secret of good exception-based code is in C++ I don't know, but I'm sure this ain't it.

Notes: 

More fields may be available via dynamicdata ..