Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

exceptions.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/Logger.h> // IWYU pragma: keep
35 #include <ogdf/basic/basic.h>
37 
38 #include <exception>
39 #include <iostream> // IWYU pragma: keep
40 
41 namespace ogdf {
42 
45 
47 #define OGDF_FLUSH_OUTPUTS std::cout << std::flush, ::ogdf::Logger::sfout() << std::flush
48 
58 #define OGDF_THROW_PARAM(CLASS, PARAM) OGDF_FLUSH_OUTPUTS, throw CLASS(PARAM)
59 
67 #define OGDF_THROW(CLASS) OGDF_FLUSH_OUTPUTS, throw CLASS()
68 
69 #ifdef OGDF_DEBUG
70 # undef OGDF_THROW_PARAM
71 # define OGDF_THROW_PARAM(CLASS, PARAM) \
72  OGDF_FLUSH_OUTPUTS, throw CLASS(PARAM, __FILE__, __LINE__)
73 # undef OGDF_THROW
74 # define OGDF_THROW(CLASS) OGDF_FLUSH_OUTPUTS, throw CLASS(__FILE__, __LINE__)
75 #endif
76 
78 
80 
86  Unknown,
88  NoFlow,
89  Sort,
90  Label,
91  ExternalFace,
96 
97  // The following codes are used by Abacus (think about changing them to
98  // more error describing codes)
100  DualBound,
101  NotInteger,
102  Buffer,
103  AddVar,
104  Sorter,
105  Phase,
106  Active,
107  NoSolution,
108  MakeFeasible,
109  Guarantee,
111  Strategy,
112  CloseHalf,
113  StandardPool,
114  Variable,
115  LpIf,
116  Lp,
117  Bstack,
118  LpStatus,
120  FixSet,
121  LpSub,
122  String,
123  Constraint,
124  Pool,
125  Global,
126  FsVarStat,
127  LpVarStat,
128  OsiIf,
130  Timer,
131  Array,
132  Csense,
133  BPrioQueue,
134  FixCand,
135  BHeap,
136  Poolslot,
137  SparVec,
138  Convar,
139  Ostream,
140  Hash,
141  Paramaster,
142  InfeasCon,
143 
144  STOP // INSERT NEW CODES BEFORE afcSTOP!
145 };
146 
148 
153  Unknown,
154  Coin,
155  Abacus,
156  Cgal,
159  STOP // INSERT NEW CODES BEFORE nscSTOP!
160 };
161 
163 
166 class OGDF_EXPORT Exception : std::exception {
167 private:
168  const char* m_file;
169  int m_line;
170 
171 public:
173 
177  explicit Exception(const char* file = nullptr, int line = -1) : m_file(file), m_line(line) { }
178 
180 
183  const char* file() const { return m_file; }
184 
186 
189  int line() const { return m_line; }
190 
191  const char* what() const noexcept override { return "Unknown OGDF Exception"; }
192 };
193 
195 
199 public:
201  explicit DynamicCastFailedException(const char* file = nullptr, int line = -1)
202  : Exception(file, line) { }
203 };
204 
206 
210 public:
212  explicit InsufficientMemoryException(const char* file = nullptr, int line = -1)
213  : Exception(file, line) { }
214 };
215 
217 
226 public:
228  explicit NoStdComparerException(const char* file = nullptr, int line = -1)
229  : Exception(file, line) { }
230 };
231 
233 
237 public:
239  explicit TypeNotSupportedException(const char* file = nullptr, int line = -1)
240  : Exception(file, line) { }
241 };
242 
244 
248 public:
250  explicit AlgorithmFailureException(AlgorithmFailureCode code, const char* file = nullptr,
251  int line = -1)
252  : Exception(file, line), m_exceptionCode(code) { }
253 
255  explicit AlgorithmFailureException(const char* file = nullptr, int line = -1)
256  : Exception(file, line), m_exceptionCode(AlgorithmFailureCode::Unknown) { }
257 
259  AlgorithmFailureCode exceptionCode() const { return m_exceptionCode; }
260 
261  const char* what() const noexcept override { return codeToString(m_exceptionCode); }
262 
263  static const char* codeToString(AlgorithmFailureCode code);
264 
265 private:
267 };
268 
270 
274 public:
276  explicit LibraryNotSupportedException(LibraryNotSupportedCode code, const char* file = nullptr,
277  int line = -1)
278  : Exception(file, line), m_exceptionCode(code) { }
279 
281  explicit LibraryNotSupportedException(const char* file = nullptr, int line = -1)
282  : Exception(file, line), m_exceptionCode(LibraryNotSupportedCode::Unknown) { }
283 
285  LibraryNotSupportedCode exceptionCode() const { return m_exceptionCode; }
286 
287 private:
289 };
290 
291 }
ogdf::Exception::Exception
Exception(const char *file=nullptr, int line=-1)
Constructs an exception.
Definition: exceptions.h:177
ogdf::AlgorithmFailureCode::BranchingVariable
@ BranchingVariable
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
ogdf::AlgorithmFailureCode::BranchingRule
@ BranchingRule
ogdf::NoStdComparerException
Exception thrown when a required standard comparer has not been specialized.
Definition: exceptions.h:225
ogdf::Exception
Base class of all ogdf exceptions.
Definition: exceptions.h:166
ogdf::LibraryNotSupportedCode::MissingCallbackImplementation
@ MissingCallbackImplementation
ogdf::AlgorithmFailureCode::Lp
@ Lp
ogdf::DynamicCastFailedException
Exception thrown when result of cast is 0.
Definition: exceptions.h:198
ogdf::AlgorithmFailureException::AlgorithmFailureException
AlgorithmFailureException(const char *file=nullptr, int line=-1)
Constructs an algorithm failure exception.
Definition: exceptions.h:255
ogdf::AlgorithmFailureCode::Global
@ Global
ogdf::InsufficientMemoryException
Exception thrown when not enough memory is available to execute an algorithm.
Definition: exceptions.h:209
ogdf::AlgorithmFailureCode::Sort
@ Sort
sequence not sorted
ogdf::AlgorithmFailureCode::CloseHalf
@ CloseHalf
ogdf::AlgorithmFailureCode::Label
@ Label
labelling failed
ogdf::AlgorithmFailureCode::NoSolution
@ NoSolution
ogdf::LibraryNotSupportedCode::STOP
@ STOP
ogdf::AlgorithmFailureCode::LpIf
@ LpIf
ogdf::AlgorithmFailureCode::ForbiddenCrossing
@ ForbiddenCrossing
crossing forbidden but necessary
ogdf::AlgorithmFailureCode::NotInteger
@ NotInteger
ogdf::DynamicCastFailedException::DynamicCastFailedException
DynamicCastFailedException(const char *file=nullptr, int line=-1)
Constructs a dynamic cast failed exception.
Definition: exceptions.h:201
ogdf::AlgorithmFailureCode::LpStatus
@ LpStatus
ogdf::AlgorithmFailureCode::Unknown
@ Unknown
ogdf::AlgorithmFailureCode::NoFlow
@ NoFlow
min-cost flow could not find a legal flow
ogdf::AlgorithmFailureException::m_exceptionCode
AlgorithmFailureCode m_exceptionCode
The error code specifying the exception.
Definition: exceptions.h:266
ogdf::AlgorithmFailureCode::Ostream
@ Ostream
ogdf::AlgorithmFailureCode::FixSet
@ FixSet
ogdf::AlgorithmFailureCode::Hash
@ Hash
ogdf::Exception::m_file
const char * m_file
Source file where exception occurred.
Definition: exceptions.h:168
Logger.h
Contains logging functionality.
ogdf::AlgorithmFailureCode::LpSub
@ LpSub
ogdf::AlgorithmFailureCode::String
@ String
ogdf::LibraryNotSupportedException::exceptionCode
LibraryNotSupportedCode exceptionCode() const
Returns the error code of the exception.
Definition: exceptions.h:285
ogdf::LibraryNotSupportedException::LibraryNotSupportedException
LibraryNotSupportedException(LibraryNotSupportedCode code, const char *file=nullptr, int line=-1)
Constructs a library not supported exception.
Definition: exceptions.h:276
ogdf::AlgorithmFailureException
Exception thrown when an algorithm realizes an internal bug that prevents it from continuing.
Definition: exceptions.h:247
ogdf::AlgorithmFailureCode::Csense
@ Csense
ogdf::LibraryNotSupportedCode
LibraryNotSupportedCode
Code for the library which was intended to get used, but its use is not supported.
Definition: exceptions.h:152
ogdf::LibraryNotSupportedCode::Abacus
@ Abacus
ABACUS not supported.
ogdf::LibraryNotSupportedCode::Cgal
@ Cgal
CGAL not supported.
ogdf::AlgorithmFailureCode::Guarantee
@ Guarantee
ogdf::Exception::file
const char * file() const
Returns the name of the source file where exception was thrown.
Definition: exceptions.h:183
ogdf::AlgorithmFailureCode::Constraint
@ Constraint
ogdf::AlgorithmFailureCode::MakeFeasible
@ MakeFeasible
ogdf::AlgorithmFailureCode::Strategy
@ Strategy
ogdf::AlgorithmFailureCode::BPrioQueue
@ BPrioQueue
ogdf::AlgorithmFailureCode::OsiIf
@ OsiIf
ogdf::AlgorithmFailureCode::Array
@ Array
ogdf::AlgorithmFailureCode::DualBound
@ DualBound
ogdf::AlgorithmFailureCode::Convar
@ Convar
ogdf::InsufficientMemoryException::InsufficientMemoryException
InsufficientMemoryException(const char *file=nullptr, int line=-1)
Constructs an insufficient memory exception.
Definition: exceptions.h:212
ogdf::AlgorithmFailureCode::AddVar
@ AddVar
config_autogen.h
ogdf::AlgorithmFailureCode::Active
@ Active
ogdf::AlgorithmFailureCode::Timer
@ Timer
ogdf::NoStdComparerException::NoStdComparerException
NoStdComparerException(const char *file=nullptr, int line=-1)
Constructs a no standard comparer available exception.
Definition: exceptions.h:228
ogdf::AlgorithmFailureException::exceptionCode
AlgorithmFailureCode exceptionCode() const
Returns the error code of the exception.
Definition: exceptions.h:259
ogdf::LibraryNotSupportedCode::Unknown
@ Unknown
ogdf::AlgorithmFailureCode::InfeasCon
@ InfeasCon
ogdf::AlgorithmFailureCode::Sorter
@ Sorter
ogdf::Exception::what
const char * what() const noexcept override
Definition: exceptions.h:191
ogdf::AlgorithmFailureCode::PrimalBound
@ PrimalBound
ogdf::AlgorithmFailureCode::TimelimitExceeded
@ TimelimitExceeded
it took too long
ogdf::AlgorithmFailureCode::Pool
@ Pool
ogdf::AlgorithmFailureCode::Bstack
@ Bstack
ogdf::LibraryNotSupportedException::m_exceptionCode
LibraryNotSupportedCode m_exceptionCode
The error code specifying the exception.
Definition: exceptions.h:288
ogdf::AlgorithmFailureCode::Paramaster
@ Paramaster
ogdf::AlgorithmFailureCode::BHeap
@ BHeap
ogdf::AlgorithmFailureCode::NoSolutionFound
@ NoSolutionFound
couldn't solve the problem
ogdf::AlgorithmFailureCode::Variable
@ Variable
basic.h
Basic declarations, included by all source files.
OGDF_EXPORT
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:101
ogdf::AlgorithmFailureCode::FsVarStat
@ FsVarStat
ogdf::AlgorithmFailureCode::SparVec
@ SparVec
ogdf::AlgorithmFailureCode::IllegalParameter
@ IllegalParameter
function parameter is illegal
ogdf::AlgorithmFailureCode::Phase
@ Phase
ogdf::TypeNotSupportedException
Exception thrown when a data type is not supported by a generic function.
Definition: exceptions.h:236
ogdf::AlgorithmFailureCode::Poolslot
@ Poolslot
ogdf::AlgorithmFailureCode::IndexOutOfBounds
@ IndexOutOfBounds
index out of bounds
ogdf::AlgorithmFailureCode::Buffer
@ Buffer
ogdf::AlgorithmFailureException::AlgorithmFailureException
AlgorithmFailureException(AlgorithmFailureCode code, const char *file=nullptr, int line=-1)
Constructs an algorithm failure exception.
Definition: exceptions.h:250
ogdf::AlgorithmFailureCode::StandardPool
@ StandardPool
ogdf::AlgorithmFailureException::what
const char * what() const noexcept override
Definition: exceptions.h:261
ogdf::LibraryNotSupportedException
Exception thrown when an external library shall be used which is not supported.
Definition: exceptions.h:273
ogdf::LibraryNotSupportedCode::FunctionNotImplemented
@ FunctionNotImplemented
the used library doesn't support that function
ogdf::AlgorithmFailureCode::STOP
@ STOP
ogdf::AlgorithmFailureCode::FixCand
@ FixCand
ogdf::LibraryNotSupportedCode::Coin
@ Coin
COIN not supported.
ogdf::AlgorithmFailureCode::ConBranchRule
@ ConBranchRule
ogdf::LibraryNotSupportedException::LibraryNotSupportedException
LibraryNotSupportedException(const char *file=nullptr, int line=-1)
Constructs a library not supported exception.
Definition: exceptions.h:281
ogdf::Exception::m_line
int m_line
Line number where exception occurred.
Definition: exceptions.h:169
ogdf::Exception::line
int line() const
Returns the line number where the exception was thrown.
Definition: exceptions.h:189
ogdf::AlgorithmFailureCode
AlgorithmFailureCode
Code for an internal failure condition.
Definition: exceptions.h:85
ogdf::TypeNotSupportedException::TypeNotSupportedException
TypeNotSupportedException(const char *file=nullptr, int line=-1)
Constructs a type-not-supported exception.
Definition: exceptions.h:239
ogdf::AlgorithmFailureCode::ExternalFace
@ ExternalFace
external face not correct
ogdf::AlgorithmFailureCode::LpVarStat
@ LpVarStat