E-MailRelay

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

gexception.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2018 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 // ===
17 ///
18 /// \file gexception.h
19 ///
20
21 #ifndef G_EXCEPTION_H
22 #define G_EXCEPTION_H
23
24 #include "gdef.h"
25 #include <string>
26 #include <iostream>
27
28 namespace G
29 {
30 class Exception ;
31 }
32
33 /// \class G::Exception
34 /// A general-purpose exception class derived from std::exception and containing
35 /// a std::string. Provides constructors that simplify the assembly of multi-part
36 /// error messages.
37 ///
38 /// Usage:
39 /// \code
40 /// throw G::Exception( "initialisation error" , "no such file" , path ) ;
41 /// \endcode
42 ///
43 class G::Exception : public std::exception
44 {
45 protected:
46 std::string m_what ;
47
48 public:
49 explicit Exception( const char * what ) ;
50 ///< Constructor.
51
52 explicit Exception( const std::string & what ) ;
53 ///< Constructor.
54
55 Exception( const char * what , const std::string & more ) ;
56 ///< Constructor.
57
58 Exception( const std::string & what , const std::string & more ) ;
59 ///< Constructor.
60
61 Exception( const std::string & what , const std::string & more1 , const std::string & more2 ) ;
62 ///< Constructor.
63
64 Exception( const std::string & what , const std::string & more1 , const std::string & more2 , const std::string & more3 ) ;
65 ///< Constructor.
66
67 virtual ~Exception() g__noexcept ;
68 ///< Destructor.
69
70 virtual const char * what() const g__noexcept override ;
71 ///< Override from std::exception.
72
73 void prepend( const char * context ) ;
74 ///< Prepends context to the what string.
75 ///< Inserts a separator as needed.
76
77 void append( const char * more ) ;
78 ///< Appends 'more' to the what string.
79 ///< Inserts a separator as needed.
80
81 void append( const std::string & more ) ;
82 ///< Appends 'more' to the what string.
83 ///< Inserts a separator as needed.
84 } ;
85
86 #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) {} class_name(const std::string &more1,const std::string &more2,const std::string &more3) : G::Exception(description,more1,more2,more3) {} }
87
88 #ifndef G_EXCEPTION
89 #define G_EXCEPTION( class_name , description ) G_EXCEPTION_CLASS( class_name , description )
90 #endif
91
92 #endif
G::Exception::what
virtual const char * what() const g__noexcept override
Override from std::exception.
Definition: gexception.cpp:65
G::Exception::Exception
Exception(const char *what)
Constructor.
Definition: gexception.cpp:24
G::Exception::prepend
void prepend(const char *context)
Prepends context to the what string.
Definition: gexception.cpp:88
G
Low-level classes.
Definition: garg.h:29
G::Exception::~Exception
virtual ~Exception() g__noexcept
Destructor.
Definition: gexception.cpp:61
G::Exception::append
void append(const char *more)
Appends 'more' to the what string.
Definition: gexception.cpp:70
G::Exception
A general-purpose exception class derived from std::exception and containing a std::string.
Definition: gexception.h:43