🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Lars Farm Tue, 24 Oct 1995 19:16
diagnostic exceptions
#2295
Author: Lars Farm
Date: Tue, 24 Oct 1995 19:16
50 lines
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. ]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads