noone wrote:
> On Mon, 22 Jan 2007 20:54:05 -0800, Michael wrote:
>
> > Here's how I've solved this in the past:
> >
> > 1) Create a virtual method 'output,' as you suggested virtual ostream&
> > output(ostream& s) const;
>
> Yes. I was hoping to avoid this but you are confirming my suspicions
>
> > It seems a little yucky, but the yuckiness is localized to your exception
> > hierarchy, the code that uses it is clean.
>
> Yeah...yucky, but if it works and is maintainable then it's OK by me. I
> just had to see if someone could think of something more elegant before I
> go that route in the morning.
The best way to deal with an over-engineered solution is not to look
for ways to under-engineer its integration into the program.
Instead, I would recommend adopting a solution more in line with the
scope of the problem that needs to be solved.
Specifically - and I feel that I must square with you - there is no
such thing as an "exception hierarchy." There is no literature that
describes "exception hierarchies", there are no experts who study them
for a living, no journals dedicated to their research - in short,
nothing.
Nor is there much value in thinking about exceptions as a "hierarchy"
in the first place. In fact, few mental models could be any less
accurate. In reality exceptions are nearly all identical - only the
particulars of error itself vary. Therefore I think it would be more
productive (and a lot less work) to replace the elaborate exception
class hiearchy with a single exception type. And have this type simply
store the exception's useful information - which could include:
1. an exception id to uniquely identify the error (int)
2. description as a string (for diagnostic messages)
3. point at which exception was thrown (filename, line number)
4. other exception-specific information
After all, the goal of this work should be for the program make the
best use out of C++ expections. The goal should not be how to take an
elaborate class hiearachy that happens to be lying around, stick it
into a program so that a) it will do something useful and b) won't
require a lot of work to get to point a).
Or to put it another way: the focus should never be on finishing the
solution - the focus should always be on eliminating the problem.
Greg
|