GG
Exception.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /* GG is a GUI for SDL and OpenGL.
3  Copyright (C) 2003-2008 T. Zachary Laine
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public License
7  as published by the Free Software Foundation; either version 2.1
8  of the License, or (at your option) 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 GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free
17  Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18  02111-1307 USA
19 
20  If you do not wish to comply with the terms of the LGPL please
21  contact the author as other terms are available for a fee.
22 
23  Zach Laine
24  whatwasthataddress@gmail.com */
25 
29 #ifndef _GG_Exception_h_
30 #define _GG_Exception_h_
31 
32 #include <GG/Export.h>
33 
34 #include <stdexcept>
35 #include <string>
36 
37 
38 namespace GG {
39 
45 class GG_API ExceptionBase : public std::exception
46 {
47 public:
48  ExceptionBase() throw() {}
49  ExceptionBase(const std::string& msg) throw() : m_msg(msg) {}
50  ~ExceptionBase() throw() {}
51 
52  virtual const char* type() const throw() = 0;
53  virtual const char* what() const throw() {return m_msg.c_str();}
54 
55 private:
56  std::string m_msg;
57 };
58 
61 #define GG_EXCEPTION( name ) \
62  class GG_API name : public ExceptionBase \
63  { \
64  public: \
65  name () throw() : ExceptionBase() {} \
66  name (const std::string& msg) throw() : ExceptionBase(msg) {} \
67  virtual const char* type() const throw() \
68  {return "GG::" # name ;} \
69  };
70 
74 #define GG_ABSTRACT_EXCEPTION( name ) \
75  class GG_API name : public ExceptionBase \
76  { \
77  public: \
78  name () throw() : ExceptionBase() {} \
79  name (const std::string& msg) throw() : ExceptionBase(msg) {} \
80  virtual const char* type() const throw() = 0; \
81  };
82 
86 #define GG_CONCRETE_EXCEPTION( name, class_name, superclass ) \
87  class GG_API name : public superclass \
88  { \
89  public: \
90  name () throw() : superclass () {} \
91  name (const std::string& msg) throw() : superclass (msg) {} \
92  virtual const char* type() const throw() \
93  {return # class_name "::" # name ;} \
94  };
95 
96 } // namespace GG
97 
98 #endif