X3J16/94-0088, WG21/N0475 1 Doc No: X3J16/94-0088, WG21/N0475 Date: 31 May 94 Project: Programming Language C++ Reply to: Michael J. Vilot ObjectCraft, Inc. 7 Colby Ct., suite #4P321 Bedford NH USA 03110P6427 mjv@objects.mv.com Clause 17 Organization This proposal is for some minor changes to the contents of the Standard C++ library. The most substantial technical change in this proposal involves re-organizing the predefined exceptions. Rather than lumping them under the heading RLanguage support,S the exception hierarchy is defined in a new header, . The three required language support exceptions are taken out of this hierarchy, simplified, and left in their respective headers. 2. Proposal 2.1. Predefined exceptions Add a new subclause: 17.3. Diagnostics Add the header . Move the specifications of the classes domain, exception, invalid_argument, length_error, logic, out_of_range, overflow, range, and runtime to this subclause. Change the names of the following exception classes: Old New domain domain_error logic logic_error overflow overflow_error range range_error runtime runtime_error Add the following Table: Predefined exceptions exception logic_error domain_error invalid_argument length_error out_of_range runtime_error overflow_error range_error 2.2. bad_alloc, bad_cast, and bad_typeid exceptions Changes to subclause:1 17.2. Language support Rename the alloc exception to bad_alloc. Remove class exception as a base class of the three exception classes bad_alloc, bad_cast, and bad_typeid. Remove virtual member functions from these three exception classes. Change the class interfaces to the following Q 17.2.4. Dynamic memory management In header : class bad_alloc { public: bad_alloc(const char* msg); const char* what() const; }; 17.2.5. Type identification In header : class bad_cast { public: bad_cast(const char* msg); const char* what() const; }; class bad_typeid { public: bad_typeid(const char* msg); const char* what() const; }; 2.3. Hander function typedefs Changes to subclause: 17.2. Language support 17.2.4. Dynamic memory management In header : typedef void (*new_handler)(); The type of a handler function to be called by operator new() or operator new[]() when they cannot satisfy a request for additional storage. The required behavior of a new_handler is to perform one of the following: Q make more storage available for allocation and then return; Q throw an exception of type bad_alloc; Q call either abort() or exit(). The default behavior of the implementationUs new_handler is to throw an exception of type bad_alloc. 17.2.6. Exception handling In header : typedef void (*terminate_handler)(); The type of a handler function to be called by terminate() when terminating exception processing. The required behavior of a terminate_handler is to terminate execution of the program without returning to the caller. The default behavior of the implementationUs terminate_handler is to call abort(). typedef void (*unexpected_handler)(); The type of a handler function to be called by unexpected() when a function attempts to throw an exception not listed in its exception-specification. The required behavior of an unexpected_handler is to throw an exception or terminate execution of the program without returning to the caller. An unexpected_handler may perform any of the following: Q rethrow the exception; Q throw another exception; Q call terminate(); Q call either abort() or exit(). The default behavior of the implementationUs unexpected_handler is to call terminate(). 2.4. Header changes Change the header to . Name the header , instead of . Delete the header . 3. Discussion 3.1. Predefined exceptions The new subclause and header are justified by the fact that these exceptions are not RLanguage support.S Rather, they are RLibrary support.S Further, they may be useful to any C++ program, especially to the extent that the programUs errors can be categorized in the manner described in 94P0021/N0408, RA Proposed Exception Class Hierarchy.S They should therefore be usable independently (for example, as base classes for further specialization). The new names call attention to the special purpose of these classes, especially when lumped together with the other standard classes (for example, in an alphabetical listing). The new Table is an attempt to represent the exception inheritance hierarchy. Something similar will be required for iostreams. 3.2. bad_alloc, bad_cast, and bad_typeid exceptions The three exceptions are indeed the RLanguage supportS exceptions. Given the extent of the debate regarding their overhead, it seems reasonable to decouple these three from the rest of the library. The (yet another) renaming to bad_alloc emphasizes the nature of these three classes. Making these exceptions non-derived classes and leaving their definitions in the appropriate language support header avoids dragging in the exception hierarchy machinery. Changing from string to const char* arguments avoids issues of dynamic allocation of strings, and avoids the overheads from this part of the library. 3.3. Hander function typedefs These were part of the proposal 92-0084/N0161, as voted on and approved at the Boston meeting in November, 1992. They were in Chapter 17 of the WP drafts throughout 1993, but were quietly dropped in the San Diego rewrite. The wording for handler function semantics follows that of the WP as of 94-0027/N0414 (March 1994). 3.4. Header changes The header , proposed in 93-0109/N0316, was adopted at the San Jose meeting in November, 1993. Given that it duplicates the declarations of ptrdiff_t, size_t, and wint_t, the new name emphasizes its parallel with the Standard C header. The name was never mentioned in proposal 94-0008/N0395, adopted at the San Diego meeting in March, 1994. The new name leaves room for additional Rraw memoryS-related components, such as the garbage-collecting Rsmart pointerS proposed in 94-0073/N0460, RTSmart PointerU Templates: Some New PossibilitiesS and 94-0097/N0484, RSmart Pointer Templates for Garbage Collection.S There seems little justification or need for the last header. 1SEE ALSO: 94-0087/N0474, Clause 17 Introduction (Editorial) for revised subclause numbering.