Article View: comp.std.c++
Article #2940Nested Exception Classes
From: Ross Dargahi (MERC)
Date: Thu, 14 Dec 1995 23:28
Date: Thu, 14 Dec 1995 23:28
63 lines
2647 bytes
2647 bytes
Consider:
class BaseException {};
class BaseClass
{
public:
class Exception: public BaseException {};
class BaseException1: public Exception {};
};
class DerivedClass1: public BaseClass
{
public:
class Exception: public Base::Exception {};
class Derived1Exception1: public Exception {};
};
class DerivedClass2: public DerivedClass1
{
public:
class Exception: public DerivedClass1::Exception {};
class Derived2Exception1: public Exception {};
};
Do I really need the class Exception classes (the ones named Exception ) in
DerivedClass1 and DerivedClass2 (The only reason I can think of doing this is
if I wanted to added class specific information to the class e.g. the name of
the class actually throwing the exception) since I will have access to class
Exception by inheritance from BaseClass ?
Is it legal to in fact have the class Exception classes in the derived
classes or should this be an error (my guess is it should be legal since
BaseClass::Exception is in a different scope than Derived1Class1::Exception
etc...)
If I only have class Exception defined in BaseClass and in some method of
class DerivedClass2 I throw a Derived2Exception1 will all of the following
catch clauses catch the exception (methinks yes) ?
catch (DerivedClass2::Exception)
catch (DerivedClass1::Exception)
catch (BaseClass::Exception)
catch (BaseException)
Cheers
Ross
==============================================================================
Ross Dargahi
Knight-Ridder Information, Inc., email: rossd@dnt.dialog.com
2440 El Camino Real, Tel: 415.254.8124
Mountain View, California 94040, USA. Fax: 415.254.8058
==============================================================================
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<4aqa5i$5p@iserv.dnt.dialog.com>Path:
arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamageShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage From: rossd@dnt.dialog.com (Ross Dargahi (MERC)) Newsgroups: comp.std.c++ Subject: Nested Exception Classes Date: 14 Dec 1995 23:28:03 GMT Organization: Knight-Ridder Information, Inc. Approved: clamage@eng.sun.com (comp.std.c++) Distribution: us Message-ID: <4aqa5i$5p@iserv.dnt.dialog.com> Reply-To: rossd@dnt.dialog.com NNTP-Posting-Host: taumet.eng.sun.com Content-Type: text X-Nntp-Posting-Host: churchill.dnt.dialog.com X-Newsreader: knews 0.9.3 Content-Length: 1793 X-Lines: 59 Originator: clamage@taumet