home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 May / PCFMay2001.iso / Xenon / C++ / FreeCommandLineTools.exe / Include / except.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-31  |  3.2 KB  |  155 lines

  1. /*  except.h
  2.  
  3.     Definitions for exception handling
  4.  
  5. */
  6.  
  7. /*
  8.  *      C/C++ Run Time Library - Version 10.0
  9.  *
  10.  *      Copyright (c) 1992, 2000 by Inprise Corporation
  11.  *      All Rights Reserved.
  12.  *
  13.  */
  14.  
  15. /* $Revision:   9.16  $ */
  16.  
  17.  
  18. #ifndef __EXCEPT_H
  19. #define __EXCEPT_H
  20. #pragma option push -b -a8 -pc -Vx- -Ve- -w-inl -w-aus -w-sig
  21.  
  22. #ifndef __cplusplus
  23. #  error Must use C++ for except.h
  24. #endif
  25.  
  26. #if !defined(___STDLIB_H)
  27. #  include <stdlib.h>
  28. #endif
  29.  
  30. #if !defined(__STD_EXCEPTION)
  31. #  include <exception>
  32. #endif
  33.  
  34. // forward declare string
  35. namespace std {
  36.  
  37. template<class charT> struct _RWSTDExportTemplate char_traits;
  38. template<class T> class _RWSTDExportTemplate allocator;
  39.  
  40. template<class charT, class traits, class Allocator> class _RWSTDExportTemplate
  41. basic_string;
  42.  
  43. typedef basic_string<char, char_traits<char>, allocator<char> > string;
  44.  
  45. }
  46.  
  47. #if !defined(RC_INVOKED)
  48.  
  49. #pragma pack(push, 1)
  50. #pragma option push -Vo-     // set standard C++ options
  51.  
  52. #if defined(__STDC__)
  53. #pragma warn -nak
  54. #endif
  55.  
  56. #endif  /* !RC_INVOKED */
  57.  
  58.  
  59. namespace std {
  60. typedef void (_RTLENTRY *terminate_handler)();
  61. typedef void (_RTLENTRY *unexpected_handler)();
  62.  
  63.  
  64. terminate_handler  _RTLENTRY set_terminate(terminate_handler);
  65. unexpected_handler _RTLENTRY set_unexpected(unexpected_handler);
  66.  
  67. void  _RTLENTRY terminate();
  68. void  _RTLENTRY unexpected();
  69. bool  _RTLENTRY uncaught_exception();
  70. } // std
  71.  
  72. #ifndef __STDC__
  73. // For backwards compatibility ...
  74. typedef std::unexpected_handler unexpected_function;
  75. typedef std::terminate_handler terminate_function;
  76. #pragma obsolete terminate_function
  77. #pragma obsolete unexpected_function
  78. #endif // !__STDC__
  79.  
  80.  
  81. extern  char *      _RTLENTRY __ThrowFileName();
  82. extern  unsigned    _RTLENTRY __ThrowLineNumber();
  83. extern  char *      _RTLENTRY __ThrowExceptionName();
  84.  
  85. #define  __throwFileName      __ThrowFileName()
  86. #define  __throwLineNumber    __ThrowLineNumber()
  87. #define  __throwExceptionName __ThrowExceptionName()
  88.  
  89. class _EXPCLASS xmsg : public std::exception
  90. {
  91. public:
  92.     xmsg(const std::string &msg);
  93.     xmsg(const xmsg &);
  94.     virtual ~xmsg() throw();
  95.     xmsg & operator=(const xmsg &);
  96.  
  97.     virtual const char * what() const throw();
  98.     const std::string & why() const;
  99.     void                raise() throw(xmsg);
  100.  
  101. private:
  102.     std::string *str;
  103. };
  104.  
  105. inline const std::string & xmsg::why() const
  106. {
  107.     return *str;
  108. };
  109.  
  110. /* The xalloc class is here for backwards compatibility ONLY!  Operator new
  111.    will not throw one of these anymore.  Operator new now throws a bad_alloc
  112.    instead.
  113. */
  114.  
  115. class _EXPCLASS xalloc : public xmsg
  116. {
  117. public:
  118.     xalloc(const std::string &msg, _SIZE_T size);
  119.  
  120.     _SIZE_T requested() const;
  121.     void    raise() throw(xalloc);
  122.  
  123. private:
  124.     _SIZE_T siz;
  125. };
  126.  
  127.  
  128. inline xalloc::xalloc(const std::string &msg, _SIZE_T size)
  129.     : xmsg(msg), siz(size)
  130. {
  131. }
  132.  
  133. inline _SIZE_T xalloc::requested() const
  134. {
  135.     return siz;
  136. }
  137.  
  138. #pragma obsolete xalloc
  139. #pragma obsolete xmsg
  140.  
  141. #if !defined(RC_INVOKED)
  142.  
  143. #if defined(__STDC__)
  144. #pragma warn .nak
  145. #endif
  146.  
  147. #pragma option pop      // restore user C++ options
  148. /* restore default packing */
  149. #pragma pack(pop)
  150.  
  151. #endif  /* !RC_INVOKED */
  152.  
  153. #pragma option pop
  154. #endif  // __EXCEPT_H
  155.