exception.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. //=======================================================================
  2. // Copyright 2002 Indiana University.
  3. // Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek
  4. //
  5. // Distributed under the Boost Software License, Version 1.0. (See
  6. // accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //=======================================================================
  9. #ifndef BOOST_GRAPH_EXCEPTION_HPP
  10. #define BOOST_GRAPH_EXCEPTION_HPP
  11. #include <stdexcept>
  12. #include <string>
  13. #include <boost/config.hpp>
  14. namespace boost
  15. {
  16. struct BOOST_SYMBOL_VISIBLE bad_graph : public std::invalid_argument
  17. {
  18. bad_graph(const std::string& what_arg) : std::invalid_argument(what_arg) {}
  19. };
  20. struct BOOST_SYMBOL_VISIBLE not_a_dag : public bad_graph
  21. {
  22. not_a_dag() : bad_graph("The graph must be a DAG.") {}
  23. };
  24. struct BOOST_SYMBOL_VISIBLE negative_edge : public bad_graph
  25. {
  26. negative_edge()
  27. : bad_graph("The graph may not contain an edge with negative weight.")
  28. {
  29. }
  30. };
  31. struct BOOST_SYMBOL_VISIBLE negative_cycle : public bad_graph
  32. {
  33. negative_cycle() : bad_graph("The graph may not contain negative cycles.")
  34. {
  35. }
  36. };
  37. struct BOOST_SYMBOL_VISIBLE not_connected : public bad_graph
  38. {
  39. not_connected() : bad_graph("The graph must be connected.") {}
  40. };
  41. struct BOOST_SYMBOL_VISIBLE not_complete : public bad_graph
  42. {
  43. not_complete() : bad_graph("The graph must be complete.") {}
  44. };
  45. struct BOOST_SYMBOL_VISIBLE graph_exception : public std::exception
  46. {
  47. ~graph_exception() throw() BOOST_OVERRIDE {}
  48. const char* what() const throw() BOOST_OVERRIDE = 0;
  49. };
  50. struct BOOST_SYMBOL_VISIBLE bad_parallel_edge : public graph_exception
  51. {
  52. std::string from;
  53. std::string to;
  54. mutable std::string statement;
  55. bad_parallel_edge(const std::string& i, const std::string& j)
  56. : from(i), to(j)
  57. {
  58. }
  59. ~bad_parallel_edge() throw() BOOST_OVERRIDE {}
  60. const char* what() const throw() BOOST_OVERRIDE
  61. {
  62. if (statement.empty())
  63. statement = std::string("Failed to add parallel edge: (") + from
  64. + "," + to + ")\n";
  65. return statement.c_str();
  66. }
  67. };
  68. struct BOOST_SYMBOL_VISIBLE directed_graph_error : public graph_exception
  69. {
  70. ~directed_graph_error() throw() BOOST_OVERRIDE {}
  71. const char* what() const throw() BOOST_OVERRIDE
  72. {
  73. return "read_graphviz: "
  74. "Tried to read a directed graph into an undirected graph.";
  75. }
  76. };
  77. struct BOOST_SYMBOL_VISIBLE undirected_graph_error : public graph_exception
  78. {
  79. ~undirected_graph_error() throw() BOOST_OVERRIDE {}
  80. const char* what() const throw() BOOST_OVERRIDE
  81. {
  82. return "read_graphviz: "
  83. "Tried to read an undirected graph into a directed graph.";
  84. }
  85. };
  86. } // namespace boost
  87. #endif // BOOST_GRAPH_EXCEPTION_HPP