- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

gexception.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2013 Graeme Walker <graeme_walker@users.sourceforge.net>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // ===
20
21 #ifndef G_EXCEPTION_H
22 #define G_EXCEPTION_H
23
24 #include "gdef.h"
25 #include <string>
26 #include <iostream>
27
29 namespace G
30 {
31 class Exception ;
32 }
33
44 class G::Exception : public std::exception
45 {
46 protected:
47 std::string m_what ;
48
49 public:
50 Exception() ;
52
53 explicit Exception( const char * what ) ;
55
56 explicit Exception( const std::string & what ) ;
58
59 Exception( const char * what , const std::string & more ) ;
61
62 Exception( const std::string & what , const std::string & more ) ;
64
65 Exception( const std::string & what , const std::string & more1 , const std::string & more2 ) ;
67
68 virtual ~Exception() throw() ;
70
71 virtual const char * what() const throw() ;
73
74 void prepend( const char * context ) ;
77
78 void append( const char * more ) ;
81
82 void append( const std::string & more ) ;
85 } ;
86
87 #define G_EXCEPTION_CLASS( class_name , description ) class class_name : public G::Exception { public: class_name() : G::Exception(description) {} explicit class_name(const char *more) : G::Exception(description,more) {} explicit class_name(const std::string &more) : G::Exception(description,more) {} class_name(const std::string &more1,const std::string &more2) : G::Exception(description,more1,more2) {} }
88
90 #ifdef USE_SMALL_EXCEPTIONS
91 #define G_EXCEPTION( fn_name , description ) static inline int fn_name() { throw G::Exception(description) ; return 0 ; } static inline int fn_name( const std::string & more ) { throw G::Exception(description,more) ; return 0 ; }
92 #else
93 #define G_EXCEPTION( class_name , description ) G_EXCEPTION_CLASS( class_name , description )
94 #endif
95
96 #endif
G::Exception::m_what
std::string m_what
Definition: gexception.h:47
G::Exception::prepend
void prepend(const char *context)
Prepends context to the what string.
Definition: gexception.cpp:85
G::Exception::~Exception
virtual ~Exception()
Destructor.
Definition: gexception.cpp:58
G::Exception::Exception
Exception()
Default constructor.
Definition: gexception.cpp:24
G
Low-level classes.
G::Exception::append
void append(const char *more)
Appends 'more' to the what string.
Definition: gexception.cpp:67
G::Exception
A general-purpose exception class derived from std::exception and containing a std::string.
Definition: gexception.h:44
G::Exception::what
virtual const char * what() const
Override from std::exception.
Definition: gexception.cpp:62