[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Exception base class



Christian Reiniger wrote:

> Hi,
>
> This is about something I found in PenguinPlay.h...
> I added some comments in square brackets []

OK I'm happy about input on this because the exception stuff was just something
Iknocked  up really quickly without thinking.  Even when I wrote it I knew it
was wrong,
but I wanted to get to other stuff.


>
>
> //
> // Base exception class.
> // Later we might feel the need to make this thing a bit cleverer.
> //
> class ppException{
>
>   char* class_string;
>
> [I'd suggest having three fields here (see my notes at the bottom for the
> "const"):
>   // Name of the class::method throwing the exception
>   const char *EOrigin;
>   // Description of the exception class (see notes at bottom)
>   const char *EType;
>   // Description of the specific problem
>   const char *Detail;

OK.


> With such a class we'd have code like this:
>
> class BillsEmpire
> {
> veryprivate:

The veryprivate keyword is a MSVC++ extention only available on the intern
MS version of the tool.It has the amazing property that when any constructs
declared veryprivate are "lost" when the source
is sent to a competitor to be used as evidence in a legal suite.  See slashdot.

Despite these wonderful properties, I feel we should warn developers against
using it, since it has some
portability problems.  (But then I guess, if NT is POSIX compliant, then just
about anything could fit
just about any standard).

> I'm using string constants intentionally because they don't need any memory
> allocation/complex operations etc and thus lower the risk of screwing
> things up even more by throwing an exception.

ARGHH Bloody C/C++ definition syntax.

I spend _ages_ looking at the "const" thing thinking that you wanted the
_pointers_ to be
immutable rather than the strings they pointed to.  Anyway now that I regained
my sanity
I'll say something.

You are right.  In any case a user will almost always pass a string litteral to
the constructor.
And since we don't copy the string, it should be const.  (In fact under GCC you
can get a
segfault if you try to write to the address of a string litteral, so they are
effectively "const char*"
rather than "char*".