sisi4s
Loading...
Searching...
No Matches
Exception.hpp
Go to the documentation of this file.
1#ifndef EXCEPTION_DEFINED
2#define EXCEPTION_DEFINED
3
4#include <string>
5#include <sstream>
6#include <iostream>
7
8#define EXCEPTION(message) \
9 sisi4s::DetailedException((message), __FILE__, __LINE__)
10#define Assert(condition, message) \
11 if (!(condition)) throw new EXCEPTION(message);
12
13namespace sisi4s {
14class Exception {
15public:
16 virtual std::string getMessage() = 0;
17};
18
20public:
21 DetailedException(std::string const &message_,
22 std::string const &file_,
23 int line_)
24 : message(message_)
25 , file(file_)
26 , line(line_)
27 , column(0) {}
28 DetailedException(std::string const &message_,
29 std::string const &file_,
30 int line_,
31 int column_)
32 : message(message_)
33 , file(file_)
34 , line(line_)
35 , column(column_) {}
36 DetailedException(std::stringstream const &stream_,
37 std::string const &file_,
38 int line_)
39 : message(stream_.str())
40 , file(file_)
41 , line(line_) {}
42 virtual ~DetailedException() {}
43 virtual std::string getMessage() {
44 std::stringstream sStream;
45 sStream << message << std::endl << "\tat " << file << ":" << line;
46 if (column > 0) sStream << ":" << column;
47 return sStream.str();
48 }
49
50private:
51 std::string message, file;
52 int line, column;
53};
54} // namespace sisi4s
55
56#endif
Definition Exception.hpp:19
DetailedException(std::stringstream const &stream_, std::string const &file_, int line_)
Definition Exception.hpp:36
DetailedException(std::string const &message_, std::string const &file_, int line_)
Definition Exception.hpp:21
virtual std::string getMessage()
Definition Exception.hpp:43
virtual ~DetailedException()
Definition Exception.hpp:42
DetailedException(std::string const &message_, std::string const &file_, int line_, int column_)
Definition Exception.hpp:28
Definition Exception.hpp:14
virtual std::string getMessage()=0
Definition Algorithm.hpp:10