🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #3922

Must exception classes have copy constructors?

#3922
From: Alan Griffiths
Date: Fri, 05 Apr 1996 02:58
52 lines
2655 bytes
I've just tried porting some code to MSVC4 (it compiles and works with 
SC7.1 and BC4.5).

In effect it appears that the Microsoft compiler _requires_ anything 
thrown as an exception to have an accessible copy constructor.  (I've 
tended to make copy constructors private to ensure catch-by-reference
and aviod slicing bugs.)

Looking through the DWP I can't see any reason to require a copy 
constructor, but there are references to copying temporaries.

Is MSVC4 correct?

code:
class MyBaseException {
public:  MyBaseException() {}
         virtual char* what() = 0;
private: MyBaseException(const MyBaseException&);
};

class MyException1 : public  MyBaseException {
public:     virtual char* what() { return "MyException1"; }
};

int main() {
    try     {
        throw MyException1();
// error C2700: 'class MyException1' : cannot be thrown (use -W4 for more info)

// warning C4671: 'MyException1' : the copy constructor is inaccessible
    } catch (MyBaseException& e) {
        cout << "OK - got here (" << __LINE__ << ") : have a " << e.what()
		<< endl;
    } catch (...) {
        cout << "ERROR - got here (" << __LINE__ << ")" << endl;
    }
    return 0;
}


--
Alan Griffiths               | Also editor of: The ISDF Newsletter
Senior Systems Consultant,   | (An Association of C and C++ Users publication)
CCN Group Limited.           | (ISDF editor  : isdf@octopull.demon.co.uk)
(agriffiths@ma.ccngroup.com) | (For ACCU see : http://bach.cis.temple.edu/accu)

---
[ 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: <606373375wnr@ma.ccngroup.com>
Path: arc1-ca.pugleaf.net!cs.mu.OZ.AU!bounce-back

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!cs.mu.OZ.AU!bounce-back
From: Alan Griffiths <aGriffiths@ma.ccngroup.com>
Newsgroups: comp.std.c++
Subject: Must exception classes have copy constructors?
Date: 05 Apr 96 02:58:28 GMT
Organization: CCN Market Analysis
Approved: fjh@cs.mu.oz.au
Message-ID: <606373375wnr@ma.ccngroup.com>
Reply-To: aGriffiths@ma.ccngroup.com
NNTP-Posting-Host: munta.cs.mu.oz.au
X-Original-Date: Thu, 04 Apr 1996 13:52:42 GMT
Return-Path: <daemon@meeker.UCAR.EDU>
X-Newsreader: Newswin Alpha 0.6
X-Mail2News-Path: devmaccn.demon.co.uk
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBFAgUBMWSMquEDnX0m9pzZAQHhGgF+LPJN+5MlYFe6AAaqymAI3nFBi9oPP7DY
 VGOqNRoIyleuLjC3im1ZJqU+eHIINlGp
 =Bqon
Originator: fjh@munta.cs.mu.OZ.AU