src/terralib/common/Exception.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib 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 Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/common/Exception.cpp
22 
23  \brief This class is designed to declare objects to be thrown as exceptions by TerraLib.
24 */
25 
26 // TerraLib
27 #include "Exception.h"
28 
29 // STL
30 #include <ostream>
31 
33  : m_code(UNKNOWN_EXCEPTION)
34 {
35 }
36 
37 te::common::Exception::Exception(const std::string& what, int code) throw()
38  : m_code(code),
39  m_msg(what)
40 {
41 }
42 
43 te::common::Exception::Exception(const char* const what, int code) throw()
44  : m_code(code),
45  m_msg(what)
46 {
47 }
48 
49 te::common::Exception::~Exception() throw() = default;
50 
51 int te::common::Exception::code() const throw()
52 {
53  return m_code;
54 }
55 
56 const char* te::common::Exception::what() const throw()
57 {
58  return m_msg.c_str();
59 }
60 
61 const char* te::common::Exception::getClassName() const throw()
62 {
63  return "te::common::Exception";
64 }
65 
66 std::ostream& operator<<(const te::common::Exception& e, std::ostream& o)
67 {
68  o << e.getClassName() << ": " << e.what();
69 
70  return o;
71 }
72 
std::ostream & operator<<(const Exception &e, std::ostream &o)
It serializes the exception and sends it to the output stream.
std::string m_msg
The internal exception message.
virtual const char * what() const
It outputs the exception message.
virtual const char * getClassName() const
It return the exception class name.
virtual int code() const
It gets the exception code.
int m_code
The internal exception code.
virtual ~Exception()
Destructor.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...