// exception standard header
#ifndef _EXCEPTION_
#define _EXCEPTION_
#include <xstddef>

_X_STD_BEGIN


		// FORWARD REFERENCES
class exception;
typedef void (*_Prhand)(const exception&);
extern _DATA_ACCESS _Prhand _Raise_handler;
void _Throw(const exception&);

 #if __EDG__ || defined(__SUNPRO_CC)
		// CLASS exception
class exception
	{	// base of all library exceptions, EDG version
public:
	static _Prhand _Set_raise_handler(_Prhand _Pnew)
		{	// register a handler for _Raise calls
		const _Prhand _Pold = _Raise_handler;
		_Raise_handler = _Pnew;
		return (_Pold);
		}

	explicit exception(const char *_Message = _MESG("unknown")) _THROW0()
		: _Ptr(_Message)
		{	// construct from message string
		}

	exception(const exception& _Right) _THROW0()
		: _Ptr(_Right._Ptr)
		{	// construct by copying _Right
		}

	exception& operator=(const exception& _Right) _THROW0()
		{	// assign _Right
		_Ptr = _Right._Ptr;
		return (*this);
		}

	virtual ~exception()
		{	// destroy the object
		}

 #if _HAS_TRADITIONAL_STL
	virtual const char *what() const

 #else /* _HAS_TRADITIONAL_STL */
	virtual const char *what() const _THROW0()
 #endif /* _HAS_TRADITIONAL_STL */

		{	// return pointer to message string
		return (_Ptr);
		}

 #if _HAS_EXCEPTIONS
protected:

 #else /* _HAS_EXCEPTIONS */
	void _Raise() const
		{	// raise the exception
		if (_Raise_handler != 0)
			(*_Raise_handler)(*this);	// call raise handler if present

		_Doraise();	// call the protected virtual
		_RAISE(*this);	// raise this exception
		}

protected:
	virtual void _Doraise() const
		{	// perform class-specific exception handling
		}
 #endif /* _HAS_EXCEPTIONS */

	const char *_Ptr;	// the message pointer
	};

		// CLASS bad_exception
class bad_exception
	: public exception
	{	// base of all bad exceptions, EDG version
public:
 	bad_exception(const char *_Message = "bad exception")
		_THROW0()
		: exception(_Message)
		{	// construct from message string
		}  

	virtual ~bad_exception() _THROW0()
		{	// destroy the object
		}
 #if _HAS_EXCEPTIONS

 #else /* _HAS_EXCEPTIONS */

protected:
	virtual void _Doraise() const
		{	// raise this exception
		_RAISE(*this);
		}
 #endif /* _HAS_EXCEPTIONS */

	};

 #else /* __EDG__ etc. */
		// CLASS exception
class exception
	{	// base of all library exceptions, gcc version
public:
	static _Prhand _Set_raise_handler(_Prhand _Pnew);

	exception()  _THROW0()
		{
		}

	virtual ~exception();

 #if _HAS_TRADITIONAL_STL
	virtual const char *what() const;

 #else /* _HAS_TRADITIONAL_STL */
	virtual const char *what() const _THROW0();
 #endif /* _HAS_TRADITIONAL_STL */

 #if _HAS_EXCEPTIONS

 #else /* _HAS_EXCEPTIONS */

	void _Raise() const;

protected:
	virtual void _Doraise() const;
 #endif /* _HAS_EXCEPTIONS */

	};

		// CLASS bad_exception
class bad_exception
	: public exception
	{	// base of all bad exceptions, gcc version
public:
	bad_exception() _THROW0()
		{	// construct with no message string
		}

	virtual ~bad_exception() _THROW0()
		{	// destroy the object
		}

 #if _HAS_EXCEPTIONS

 #else /* _HAS_EXCEPTIONS */

protected:
	virtual void _Doraise() const
		{	// raise this exception
		_RAISE(*this);
		}
 #endif /* _HAS_EXCEPTIONS */

	};
 #endif /* __EDG__ etc. */

		// TYPES
typedef void (*terminate_handler)();
typedef void (*unexpected_handler)();

		// FUNCTION DECLARATIONS
terminate_handler set_terminate(terminate_handler) _THROW0();
unexpected_handler set_unexpected(unexpected_handler) _THROW0();
bool uncaught_exception();
_NO_RETURN(terminate());
_NO_RETURN(unexpected());

_X_STD_END

#endif /* _EXCEPTION_ */

/*
 * Copyright (c) 1992-2004 by P.J. Plauger.  ALL RIGHTS RESERVED.
 * Consult your license regarding permissions and restrictions.
V4.02:1476 */
