All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
50 {
51 }
52 
53 int te::common::Exception::code() const throw()
54 {
55  return m_code;
56 }
57 
58 const char* te::common::Exception::what() const throw()
59 {
60  return m_msg.c_str();
61 }
62 
63 const char* te::common::Exception::getClassName() const throw()
64 {
65  return "te::common::Exception";
66 }
67 
68 std::ostream& operator<<(const te::common::Exception& e, std::ostream& o)
69 {
70  o << e.getClassName() << ": " << e.what();
71 
72  return o;
73 }
74 
std::ostream & operator<<(const Exception &e, std::ostream &o)
It serializes the exception and sends it to the output stream.
Definition: Exception.cpp:68
virtual const char * what() const
It outputs the exception message.
Definition: Exception.cpp:58
virtual const char * getClassName() const
It return the exception class name.
Definition: Exception.cpp:63
virtual int code() const
It gets the exception code.
Definition: Exception.cpp:53
Exception()
Default constructor.
Definition: Exception.cpp:32
virtual ~Exception()
Destructor.
Definition: Exception.cpp:49
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
Definition: Exception.h:58
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...