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 // ===
17 //
18 // gexception.cpp
19 //
20 
21 #include "gdef.h"
22 #include "gexception.h"
23 
Exception()24 G::Exception::Exception()
25 {
26 }
27 
Exception(const char * what)28 G::Exception::Exception( const char * what ) :
29 	m_what(what?what:"")
30 {
31 }
32 
Exception(const std::string & what)33 G::Exception::Exception( const std::string & what ) :
34 	m_what(what)
35 {
36 }
37 
Exception(const char * what,const std::string & more)38 G::Exception::Exception( const char * what , const std::string & more ) :
39 	m_what(what)
40 {
41 	append( more ) ;
42 }
43 
Exception(const std::string & what,const std::string & more)44 G::Exception::Exception( const std::string & what , const std::string & more ) :
45 	m_what(what)
46 {
47 	append( more ) ;
48 }
49 
Exception(const std::string & what,const std::string & more1,const std::string & more2)50 G::Exception::Exception( const std::string & what , const std::string & more1 , const std::string & more2 ) :
51 	m_what(what)
52 {
53 	append( more1 ) ;
54 	append( more2 ) ;
55 }
56 
57 
~Exception()58 G::Exception::~Exception() throw()
59 {
60 }
61 
what() const62 const char * G::Exception::what() const throw()
63 {
64 	return m_what.c_str() ;
65 }
66 
append(const char * more)67 void G::Exception::append( const char * more )
68 {
69 	if( more != NULL && *more != '\0' )
70 	{
71 		m_what += std::string(": ") ;
72 		m_what += std::string(more) ;
73 	}
74 }
75 
append(const std::string & more)76 void G::Exception::append( const std::string & more )
77 {
78 	if( !more.empty() )
79 	{
80 		m_what += std::string(": ") ;
81 		m_what += std::string(more) ;
82 	}
83 }
84 
prepend(const char * context)85 void G::Exception::prepend( const char * context )
86 {
87 	if( context != NULL && *context != '\0' )
88 	{
89 		m_what = std::string(context) + ": " + m_what ;
90 	}
91 }
92 
93 /// \file gexception.cpp
94