alpar@906: /* -*- C++ -*- alpar@921: * src/lemon/error.h - Part of LEMON, a generic C++ optimization library alpar@906: * alpar@906: * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport alpar@906: * (Egervary Combinatorial Optimization Research Group, EGRES). alpar@906: * alpar@906: * Permission to use, modify and distribute this software is granted alpar@906: * provided that this copyright notice appears in all copies. For alpar@906: * precise terms see the accompanying LICENSE file. alpar@906: * alpar@906: * This software is provided "AS IS" with no warranty of any kind, alpar@906: * express or implied, and with no claim as to its suitability for any alpar@906: * purpose. alpar@906: * alpar@906: */ alpar@883: alpar@921: #ifndef LEMON_ERROR_H alpar@921: #define LEMON_ERROR_H alpar@883: alpar@883: //! \ingroup misc alpar@883: //! \file alpar@883: //! \brief Basic error handling (signaling) routines. alpar@883: alpar@883: #include alpar@883: #include alpar@883: #include alpar@883: alpar@883: alpar@921: namespace lemon { alpar@883: alpar@883: /** alpar@883: * \brief Generic exception class. alpar@883: * alpar@883: * \todo Do we need this? alpar@883: * alpar@883: * \todo Don't we need different kind of exceptions for different kind alpar@883: * of errors? alpar@883: * Shouldn't we use \ instead? alpar@883: */ alpar@883: class Exception : public std::exception { alpar@883: protected: alpar@883: std::ostringstream buf; alpar@883: public: alpar@883: Exception() {} alpar@883: explicit Exception(const std::string &s) { buf << s; } alpar@883: Exception(const Exception &e) : std::exception() { alpar@883: buf << e.buf.str(); alpar@883: } alpar@883: virtual ~Exception() throw() {} alpar@883: alpar@883: virtual const char* what() const throw() { alpar@883: return buf.str().c_str(); alpar@883: } alpar@883: klao@993: template klao@993: Exception& operator<<(T const& t) { buf << t; return *this; } alpar@883: }; alpar@883: alpar@883: /** alpar@883: * \brief Generic error signaling function. alpar@883: * alpar@883: * \todo Do we really need this? Is it helpful? alpar@883: */ alpar@883: inline void fault(const std::string &msg) { alpar@883: throw Exception(msg); alpar@883: } alpar@883: alpar@883: /** alpar@883: * \brief Macro for mark not yet implemented features. alpar@883: * alpar@883: * \todo Is this the right place for this? It should be used only in alpar@883: * modules under development. alpar@883: */ alpar@883: alpar@883: # define FIXME(msg) \ alpar@921: do { throw ::lemon::Exception() << "FIXME: " msg " (in: " \ klao@993: __FILE__ ", " << __LINE__ << ")"; \ alpar@883: } while(false) alpar@883: alpar@883: } alpar@921: #endif // LEMON_ERROR_H