Chapter Contents |
Previous |
Next |
Standard Libraries |
Most C++ programs need to access some of the classes and functions contained in the libraries provided with the SAS/C C++ Development System. These classes and functions are declared in header files. In addition, you can have header files of your own. Using the SAS/C C++ Development System under TSO, CMS, OS/390 Batch, and UNIX System Services , describes how header files are stored and named under your operating system. Here are some other tips to keep in mind when you use header files in C++ programs:
Use this form for your own header files:
Header Files Supplied with the Standard Libraries |
The following header files are supplied with the standard libraries:
bsamstr.h |
<cerrno> |
<clocale> |
<csetjmp> |
<cstddef> |
<cstring> |
<exception> |
iostream.h |
stream.h |
<typeinfo> |
The contents of the
bsamstr.h
, complex.h
, fstream.h
, iomanip.h
,
iostream.h
, stdiostream.h
, and strstream.h
header files are described in I/O Class Descriptions. The contents of
stream.h
are described in
stream.h header file.
The <exception> Header File |
std::set_unexpected
,
std::unexpected_handler
, and std::unexpected
Provides for unexpected exception handling.
namespace std { typedef void (*unexpected_handler)(); unexpected_handler set_unexpected(unexpected_handler) throw(); void unexpected(); }
std::unexpected
is invoked.
new_handler
pointer must not be NULL. The handler function may not return
but may throw an exception or end the program.
std::terminate
.
std::set_terminate
,
std::terminate_handler
, and std::terminate
Provides termination handling for exceptions.
namespace std { typedef void (*terminate_handler)(); terminate_handler set_terminate(terminate_handler new_handler) throw(); void terminate(); }
std::terminate()
is called. The handler function must end the program without returning.
Check for pending uncaught exceptions.
namespace std { bool uncaught_exception(); }
std::terminate()
will be called. This function can be called to determine if such a situation
might exist. Only the current coprocess is considered.
Base class for C++ run time and library exceptions.
namespace std { class exception { public: exception() throw(); exception(const exception&) throw(); exception& operator=(const exception&) throw(); virtual ~exception(); throw(); virtual const char* what() const throw(); }; }
virtual const char* what() const throw();This function returns a character string describing the exception type. Unless overridden in a derived class this string is
std::exception
or derived class
.
static void xtrace( __remote void (*writer)(const char *line) = 0 );This function dumps traceback information saved from the point of the original throw for the currently handled exception. If the function pointer is NULL, the output is sent to
stderr
unless
the SPE library is being used. See Handling Exceptions in SAS/C for more
information.
static bool is_xtraced();
xtrace
information has been output. It returns true
if the
information for the currently handled exception
was dumped by =xtrace
or an xtrace()
call.
Class for reporting unexpected exceptions.
namespace std { class bad_exception : public exception { public: bad_exception() throw(); bad_exception(const bad_exception&) throw(); bad_exception& operator=(const bad_exception&) throw(); virtual ~bad_exception(); throw(); virtual const char* what() const throw(); }; }
virtual const char* what() const throw();This function returns a character string describing the exception type. Unless overridden in a derived class, this string is as follows:
std::bad_exceptionor
derived class.
The <new> Header File |
Class for reporting allocation errors.
namespace std { class bad_alloc : public exception { public: bad_alloc() throw(); bad_alloc(const bad_alloc&) throw(); bad_alloc& operator=(const bad_alloc&) throw(); virtual ~bad_alloc(); throw(); virtual const char* what() const throw(); }; }
<new>
or <new.h>
. It
is used as an exception type for memory allocation errors. The default new
operators report memory allocation failure by throwing an object of this class
or a derived class.
std::bad_alloc
or derived
class
.
std::nothrow_t
and
std::nothrow
namespace std { struct nothrow_t {}; extern const nothrow_t nothrow; }
std::nothrow_tThis is simply an empty class.
operator new
or operator new[]
, which are described below.
operator new
tries again to allocate memory, and the process
repeats. The new-handler may also exit via throwing an exception of type std::bad_alloc
or some class publicly derived from it, in
which case operator new
exits with the exception.
If insufficient memory is available and there is no new-handler, operator new
exits by throwing an exception of type std::bad_alloc
.
This function is user-replaceable.
It should never return a NULL pointer.
size
bytes or returns NULL. If insufficient free dynamic memory
is available and a new-handler is currently defined, the new-handler is called.
If the new-handler returns, then operator new
tries again to allocate memory, and the process repeats. The new-handler
may also exit via throwing an exception of type std::bad_alloc
or some class publicly derived from it, in which case operator new
returns
a NULL pointer. If insufficient memory
is available and there is no new-handler, operator new
returns NULL. This function is user-replaceable. A pointer returned from
this version of the operator is required to be equivalent to a pointer obtained
from the standard version.
ptr
. These functions are equivalent
and should accept pointers from both the standard and non-throwing versions
of operator new
as well as NULL pointers.
Each function is user-replaceable.
operator new
declarations.
The requirements on these functions are the same as the corresponding non-array
versions. The default library versions call the corresponding non-array version.
operator new[]
declarations. The requirements on these functions are the same as the corresponding
non-array delete operators. The default library versions call the corresponding
non-array version.
operator new
is used to construct
objects at a specified location.
operator new
and operator new[]
.
std::new_handler
and
std::set_new_handler
namespace std { typedef void (*new_handler)(); new_handler set_new_handler(new_handler); }
std::set_new_handler()
.
std::set_new_handlerIs used to designate a user-defined function (a new-handler) to handle out-of-memory conditions detected by
operator new
. The new-handler is called if an operator new
function cannot
allocate any dynamic memory.
The new-handler function takes no arguments and returns void
. The new-handler should free some memory before returning
to its caller or throw an exception of type std::bad_alloc
or a class derived from it; otherwise, an endless loop could
result. If it cannot free any memory, it should throw an exception or terminate
the program via exit
, std::terminate
, or abort
. Another alternative
for the function is to remove itself as a new-handler by calling std::set_new_handler
with NULL or a pointer to some other
handler. std::set_new_handler
returns the
previous new-handler or NULL if there was not a previous new-handler.
The new.h Header File |
The <typeinfo> Header File |
Provides information on object types.
namespace std { class type_info { public: virtual ~type_info(); bool operator==(const type_info& rhs) const; bool operator!=(const type_info& rhs) const; bool before(const type_info& rhs) const; const char* name() const; }; }
typeid()
returns a reference to a const
object of this type. Such objects are created by the C++ implementation to
provide an identifier for types. The class allows two std::type_info
objects to be compared for type equivalence, or compared
for order in an arbitrary collating sequence of types. It also allows a printable
description of the represented type to be retrieved.
type_info
objects represent the same type, and returns false
otherwise.
type_info
objects represent the same type, and returns true
otherwise.
rhs
in an arbitrary collating sequence of types, and returns false otherwise.
This order is arbitrary and may change in different program loads.
type_info
object. The function calls operator
new
to allocate working storage. The result is cached, so
it should not be deallocated by the user.
Class for reporting dynamic_cast errors.
namespace std { class bad_cast : public exception { public: bad_cast() throw(); bad_cast(const bad_cast&) throw(); bad_cast& operator=(const bad_cast&) throw(); virtual ~bad_cast(); throw(); virtual const char* what() const throw(); }; }
dynamic_cast
operations. It indicates a dynamic_cast
to a
reference type when the object could not be cast to
the specified type.
std::bad_cast
or derived
class
.
Class for reporting typeid
operator errors.
namespace std { class bad_typeid : public exception { public: bad_typeid() throw(); bad_typeid(const bad_typeid&) throw(); bad_typeid& operator=(const bad_typeid&) throw(); virtual ~bad_typeid(); throw(); virtual const char* what() const throw(); }; }
typeid
operator. It is thrown when the typeid
operator is applied to an lvalue expression of the
form *p
, where p
is an expression whose value is a NULL pointer.
virtual const char* what() const throw();Returns a character string describing the exception type. Unless overridden in a derived class, this string is
std::bad_typeid
or derived class
.
Class for reporting missing RTTI type information.
namespace std { class _ _non_rtti : public exception { public: _ _non_rtti() throw(); _ _non_rtti(const _ _non_rtti&) throw(); _ _non_rtti& operator=(const _ _non_rtti&) throw(); virtual ~_ _non_rtti(); throw(); virtual const char* what() const throw(); }; }
dynamic_cast
or typeid
is applied to a object with polymorphic
type constructed in a compilation unit that was compiled without the RTTI
option.
virtual const char* what() const throw();Returns a character string describing the exception type. Unless overridden in a derived class, this string is
std::__non_rtti
or derived class
.
typeinfo.h Header File |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.