Topic: Is throw part of signature needed for overriding?


Author: "Michael S. Scherotter" <mss@tartus.com>
Date: 1998/09/21
Raw View
class Base
{
 virtual DoThis() throw (domain_error) = 0;
 virtual DoThat() = 0;
};

class Derrived : public Base
{
 virtual DoThis() {}

 virtual DoThat(int* pValue) throw (invalid_argument)
 { if (pValue == NULL) throw invalid_argument("NULL Pointer"); }
};

Is the throw statement part of the signature needed for
inheritance?  Will both of these work?

--
Michael S. Scherotter           |Architectural Design Tools
________________________________|AutoCAD Applications
Lead Software Developer         |Custom CAD Solutions
Tartus Development, Inc.        |OpenGL & Open Inventor
630 Las Gallinas Ave. Suite 300 |MFC, OLE, COM, & ATL
San Rafael, CA 94903            |OLE for Design and Modeling
                                |IAI IFC
                                |___________________________
(415) 491-8920 x 12                    mailto:mss@tartus.com
(415) 491-8921 (fax)                   http://www.tartus.com
---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: Alexandre Oliva <oliva@dcc.unicamp.br>
Date: 1998/09/21
Raw View
Michael S Scherotter <mss@tartus.com> writes:

> class Derived : public Base {
>  virtual DoThis();
        // overrides Base::DoThis()throw(domain_error)
>  virtual DoThat(int* pValue) throw (invalid_argument);
 // overrides Base::DoThat(int*), no throw clause

> Is the throw statement part of the signature needed for
> inheritance?

Yes, you can only restrict the set of exceptions a member function may
throw in it overriders or in its definition.

> Will both of these work?

No, the first one will not, because it says Derived::DoThis() can
throw any exception, but the base class promised to throw only
domain_error exceptions for this method.  The second declaration is
valid, since the base class could throw anything.

--
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil
---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]