src/lemon/attic/error.h
author deba
Thu, 11 Nov 2004 10:17:20 +0000
changeset 981 2e34b796d532
parent 907 df8472ab5d4a
permissions -rw-r--r--
maxUndirEdgeId modified to maxId(UndirEdge)
maxEdgeId modified to maxId(Edge)
alpar@906
     1
/* -*- C++ -*-
alpar@921
     2
 * src/lemon/error.h - Part of LEMON, a generic C++ optimization library
alpar@906
     3
 *
alpar@906
     4
 * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@906
     5
 * (Egervary Combinatorial Optimization Research Group, EGRES).
alpar@906
     6
 *
alpar@906
     7
 * Permission to use, modify and distribute this software is granted
alpar@906
     8
 * provided that this copyright notice appears in all copies. For
alpar@906
     9
 * precise terms see the accompanying LICENSE file.
alpar@906
    10
 *
alpar@906
    11
 * This software is provided "AS IS" with no warranty of any kind,
alpar@906
    12
 * express or implied, and with no claim as to its suitability for any
alpar@906
    13
 * purpose.
alpar@906
    14
 *
alpar@906
    15
 */
alpar@883
    16
alpar@921
    17
#ifndef LEMON_ERROR_H
alpar@921
    18
#define LEMON_ERROR_H
alpar@883
    19
alpar@883
    20
//! \ingroup misc
alpar@883
    21
//! \file
alpar@883
    22
//! \brief Basic error handling (signaling) routines.
alpar@883
    23
alpar@883
    24
#include <exception>
alpar@883
    25
#include <string>
alpar@883
    26
#include <sstream>
alpar@883
    27
alpar@883
    28
alpar@921
    29
namespace lemon {
alpar@883
    30
alpar@883
    31
  /**
alpar@883
    32
   * \brief Generic exception class.
alpar@883
    33
   *
alpar@883
    34
   * \todo Do we need this?
alpar@883
    35
   *
alpar@883
    36
   * \todo Don't we need different kind of exceptions for different kind
alpar@883
    37
   * of errors?
alpar@883
    38
   * Shouldn't we use \<stdexcept\> instead?
alpar@883
    39
   */
alpar@883
    40
  class Exception : public std::exception {
alpar@883
    41
  protected:
alpar@883
    42
    std::ostringstream buf;
alpar@883
    43
  public:
alpar@883
    44
    Exception() {}
alpar@883
    45
    explicit Exception(const std::string &s) { buf << s; }
alpar@883
    46
    Exception(const Exception &e) : std::exception() {
alpar@883
    47
      buf << e.buf.str();
alpar@883
    48
    }
alpar@883
    49
    virtual ~Exception() throw() {}
alpar@883
    50
    
alpar@883
    51
    virtual const char* what() const throw() {
alpar@883
    52
      return buf.str().c_str();
alpar@883
    53
    }
alpar@883
    54
alpar@883
    55
    Exception& operator<<(std::string const& s) { buf << s; return *this; }
alpar@883
    56
    Exception& operator<<(char const *s) { buf << s; return *this; }
alpar@883
    57
    Exception& operator<<(int i) { buf << i; return *this; }
alpar@883
    58
  };
alpar@883
    59
alpar@883
    60
  /**
alpar@883
    61
   * \brief Generic error signaling function.
alpar@883
    62
   *
alpar@883
    63
   * \todo Do we really need this? Is it helpful?
alpar@883
    64
   */
alpar@883
    65
  inline void fault(const std::string &msg) {
alpar@883
    66
    throw Exception(msg);
alpar@883
    67
  }
alpar@883
    68
alpar@883
    69
  /**
alpar@883
    70
   * \brief Macro for mark not yet implemented features.
alpar@883
    71
   *
alpar@883
    72
   * \todo Is this the right place for this? It should be used only in
alpar@883
    73
   * modules under development.
alpar@883
    74
   */
alpar@883
    75
alpar@883
    76
# define FIXME(msg) \
alpar@921
    77
    do { throw ::lemon::Exception() << "FIXME: " msg " (in: "    \
alpar@883
    78
      __FILE__ ", " << __LINE__ << ")";                         \
alpar@883
    79
    } while(false)
alpar@883
    80
alpar@883
    81
}
alpar@921
    82
#endif // LEMON_ERROR_H