General IRI utilities
exceptions.h
1 // Copyright (C) 2009-2010 Institut de Robòtica i Informàtica Industrial, CSIC-UPC.
2 // Author Sergi Hernandez (shernand@iri.upc.edu)
3 // All rights reserved.
4 //
5 // This file is part of iriutils
6 // iriutils is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU Lesser General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 
19 #ifndef _EXCEPTIONS
20 #define _EXCEPTIONS
21 
22 #include <exception>
23 #include <sstream>
24 #include <string>
25 
26 template <typename T_>
27 inline std::string tostring (const T_ & src)
28 {
29  std::ostringstream out;
30 
31  out << src;
32  return out.str();
33 }
34 
35 #define _HERE_ (std::string(__PRETTY_FUNCTION__) + " at " + \
36  std::string(__FILE__) + ":" +tostring(__LINE__))
37 
76 class CException : public std::exception
77 {
78  protected:
90  std::string error_msg;
91  public:
110  CException(const std::string& where, const std::string& error_msg);
120  virtual const std::string& what(void);
127  virtual ~CException() throw();
128 };
129 
130 #endif
CException(const std::string &where, const std::string &error_msg)
Class constructor.
Definition: exceptions.cpp:25
virtual const std::string & what(void)
Function to get the error message.
Definition: exceptions.cpp:33
virtual ~CException()
Class destructor.
Definition: exceptions.cpp:38
std::string error_msg
Exception error message.
Definition: exceptions.h:90
Generic exception.
Definition: exceptions.h:76