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