Article View: comp.std.c++
Article #4126RE: Use of standard exception classes
From: Bradd W. Szonye
Date: Sun, 21 Apr 1996 15:33
Date: Sun, 21 Apr 1996 15:33
53 lines
2886 bytes
2886 bytes
On Monday, April 15, 1996, Bob Friesenhahn wrote...
> Kevin Cline wrote:
>
> > Can someone on the committee indicate whether it was the committee's
> > intention for the standard exception class hierarchy to be used in
> > general C++ programming, or whether the intention was for the standard
> > exception class hierarchy to be reserved to the Standard C++ library?
> >
> > Another developer on our team has asked
> > How can we be sure that ANSI C++ library callbacks work
> > correctly in the face of exceptions? What if ANSI C++
> > library code catches *our* exception?
>
> A further consideration is that often it is valuable to know what
> body of code generated an exception. If all exeptions are derived
> from the same base class, then it will be impossible to tell if
> an exception occurred in standard library code, user code, or some
> third party library. An additional level of derivation could be
> used to satisfy this requirement, but since the standard exception
> classes have already been defined, there is no satisfactory place
> to insert the additional derivation.
>
> By using a different base class for each seperately maintained body
> of code, it will be possible to provide handlers for each code body
> with the additional maintenance expense of maintaining the additional
> catch blocks.
>
> Bob
I don't see this as a real problem (determining if the user's code
generated the exception). Consider this:
class user_defined_exception: virtual public exception { ... };
class user_logic_error: virtual public logic_error, virtual public
user_definded_exception { ... };
... catch (logic_error* e)
{
if (dynamic_cast<user_defined_exception>(e)) ...
}
This will tell you if the logic error you caught was one defined in your
own code or somebody else's.
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Technical Details
Message-ID:
<01bb2ee4.a9434580$65c2b7c7@Zany.localhost>Path:
arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamageReferences:
<9604121530.AA08606@sun132.spd.dsccc.com> <3171C842.64BB@cyberramp.net>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage From: "Bradd W. Szonye" <bradds@ix.netcom.com> Newsgroups: comp.std.c++ Subject: RE: Use of standard exception classes Date: 21 Apr 1996 15:33:35 GMT Organization: Netcom Approved: clamage@eng.sun.com (comp.std.c++) Message-ID: <01bb2ee4.a9434580$65c2b7c7@Zany.localhost> References: <9604121530.AA08606@sun132.spd.dsccc.com> <3171C842.64BB@cyberramp.net> NNTP-Posting-Host: taumet.eng.sun.com X-Nntp-Posting-Host: det-mi3-05.ix.netcom.com X-Netcom-Date: Sat Apr 20 1:09:55 PM CDT 1996 X-Newsreader: Microsoft Internet News Content-Length: 1804 Originator: clamage@taumet