Article View: comp.std.c++
Article #2295diagnostic exceptions
From: Lars Farm
Date: Tue, 24 Oct 1995 19:16
Date: Tue, 24 Oct 1995 19:16
50 lines
2138 bytes
2138 bytes
The diagnostic exception classes are constructed from a const string&. Will
they copy the text or store a reference to the string?
-----
19.1.1 Class logic_error [lib.logic.error]
...
logic_error(const string& what_arg);
Effects:
Constructs an object of class logic_error.
Postcondition:
what() == what_arg.data().
----- ??
Does this mean:
(1) class logic_error : public exception {
string s;
public:
logic_error(const string& what_arg) :s(what_arg){}
const char* what() const { return s.c_str(); }
};
post: strcmp( what(), what_arg.data() ) == 0
or does it mean:
(2) class logic_error : public exception {
const string& s;
public:
logic_error(const string& what_arg) :s(what_arg){}
const char* what() const { return s.data(); }
};
post: what() and what_arg.data()
shall point at the same memory location
Interpretation (1) implies that the exception object carries a copy of the
text. Then you can say throw runtime_error("error"); With (2) you must
construct diagnostic errors from global/static string objects.
throw logic_error("error"); // is this wrong?
static string text("error");
throw logic_error(text); // is this required?
--
Lars Farm, lars.farm@nts.mh.se
[ 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:
<ACB2F42C9668BCA1@sleipner.nts.mh.se>Path:
arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamageShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews2.Eng.Sun.COM!taumet!clamage From: lars.farm@nts.mh.se (Lars Farm) Newsgroups: comp.std.c++ Subject: diagnostic exceptions Date: 24 Oct 1995 19:16:26 GMT Organization: pv Approved: clamage@eng.sun.com (comp.std.c++) Message-ID: <ACB2F42C9668BCA1@sleipner.nts.mh.se> NNTP-Posting-Host: taumet.eng.sun.com Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1"; conversions="8bit" Content-Transfer-Encoding: 8bit X-Nntp-Posting-Host: @sleipner.nts.mh.se X-Lines: 46 Content-Length: 1317 Originator: clamage@taumet