home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / libg++-2.7.1-bin.lha / lib / g++-include / std / stdexcept.h < prev    next >
C/C++ Source or Header  |  1996-10-12  |  4KB  |  127 lines

  1. // Methods for Exception Support for -*- C++ -*-
  2. // Copyright (C) 1994, 1995 Free Software Foundation
  3.  
  4. // This file is part of the GNU ANSI C++ Library.  This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 2, or (at your option)
  8. // any later version.
  9.  
  10. // This library is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14.  
  15. // You should have received a copy of the GNU General Public License
  16. // along with this library; see the file COPYING.  If not, write to the Free
  17. // Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18.  
  19. // As a special exception, if you link this library with files
  20. // compiled with a GNU compiler to produce an executable, this does not cause
  21. // the resulting executable to be covered by the GNU General Public License.
  22. // This exception does not however invalidate any other reasons why
  23. // the executable file might be covered by the GNU General Public License.
  24.  
  25. // Written by Mike Stump based upon the specification in the 20 September 1994
  26. // C++ working paper, ANSI document X3J16/94-0158.
  27.  
  28. #ifndef __STDEXCEPT__
  29. #define __STDEXCEPT__
  30.  
  31. #ifdef __GNUG__
  32. #pragma interface "std/stdexcept.h"
  33. #endif
  34.  
  35. #include <typeinfo>
  36.  
  37. extern "C++" {
  38. #if 0
  39. #include <string>
  40. typedef string __string;
  41. #else
  42. typedef const char * __string;
  43. #endif
  44.  
  45. class exception {
  46. public:
  47.   typedef void (*raise_handler)(exception&);
  48.   static raise_handler set_raise_handler(raise_handler handler_arg);
  49.   exception (const __string& what_arg): desc (what_arg) { }
  50.   virtual ~exception() { }
  51.   void raise();
  52.   virtual __string what() const { return desc; }
  53. protected:
  54.   exception() { }
  55.   virtual void do_raise() { }
  56. private:
  57.   __string desc;
  58. };
  59.  
  60. class logic_error : public exception {
  61. public:
  62.   logic_error(const __string& what_arg): exception (what_arg) { }
  63.   virtual ~logic_error() { }
  64. };
  65.  
  66. class domain_error : public logic_error {
  67. public:
  68.   domain_error (const __string& what_arg): logic_error (what_arg) { }
  69.   virtual ~domain_error () { }
  70. };
  71.  
  72. class invalid_argument : public logic_error {
  73. public:
  74.   invalid_argument (const __string& what_arg): logic_error (what_arg) { }
  75.   virtual ~invalid_argument () { }
  76. };
  77.  
  78. class length_error : public logic_error {
  79. public:
  80.   length_error (const __string& what_arg): logic_error (what_arg) { }
  81.   virtual ~length_error () { }
  82. };
  83.  
  84. class out_of_range : public logic_error {
  85. public:
  86.   out_of_range (const __string& what_arg): logic_error (what_arg) { }
  87.   virtual ~out_of_range () { }
  88. };
  89.  
  90. class runtime_error : public exception {
  91. public:
  92.   runtime_error(const __string& what_arg): exception (what_arg) { }
  93.   virtual ~runtime_error() { }
  94. protected:
  95.   runtime_error(): exception () { }
  96. };
  97.  
  98. class range_error : public runtime_error {
  99. public:
  100.   range_error (const __string& what_arg): runtime_error (what_arg) { }
  101.   virtual ~range_error () { }
  102. };
  103.  
  104. class overflow_error : public runtime_error {
  105. public:
  106.   overflow_error (const __string& what_arg): runtime_error (what_arg) { }
  107.   virtual ~overflow_error () { }
  108. };
  109.  
  110. // These are moved here from typeinfo so that we can compile with -frtti
  111. class bad_cast : public logic_error {
  112. public:
  113.   bad_cast(const __string& what_arg): logic_error (what_arg) { }
  114.   virtual ~bad_cast() { }
  115. };
  116.  
  117. extern bad_cast __bad_cast_object;
  118.  
  119. class bad_typeid : public logic_error {
  120.  public:
  121.   bad_typeid (): logic_error ("bad_typeid") { }
  122.   virtual ~bad_typeid () { }
  123. };
  124. } // extern "C++"
  125.  
  126. #endif
  127.