FAST  3.2.0
Framework for Heterogeneous Medical Image Computing and Visualization
Exception.hpp
Go to the documentation of this file.
1 #ifndef EXCEPTIONS_HPP_
2 #define EXCEPTIONS_HPP_
3 
4 #include "FASTExport.hpp"
5 #include <exception>
6 #include <string>
7 #include <sstream>
8 
9 namespace fast {
10 inline std::string intToString(int number) {
11  std::stringstream ss;//create a stringstream
12  ss << number;//add number to the stream
13  return ss.str();//return a string with the contents of the stream
14 }
15 class FAST_EXPORT Exception : public std::exception {
16  public:
18  this->line = -1;
19  this->message = "";
20  this->file = "";
21  };
22  Exception(std::string message) {
23  this->line = -1;
24  this->message = message;
25  this->file = "";
26  };
27  Exception(int line, const char * file) {
28  this->line = line;
29  this->message = "";
30  this->file = file;
31  };
32  Exception(std::string message, int line, const char * file) {
33  this->message = message;
34  this->line = line;
35  this->file = file;
36  };
37  virtual const char * what() const throw() {
38  if(line > -1) {
39  std::string string = message + "\nException thrown at line " +
40  intToString(line) + " in file " + std::string(file);
41  return string.c_str();
42  } else {
43  return message.c_str();
44  }
45  };
46  void setLine(int line) {
47  this->line = line;
48  };
49  void setFile(const char * file) {
50  this->file = file;
51  };
52  void setMessage(std::string message) {
53  this->message = message;
54  };
55  ~Exception() throw() {};
56  private:
57  int line;
58  const char * file;
59  std::string message;
60 };
61 
62 class FAST_EXPORT FileNotFoundException : public Exception {
63  public:
64  FileNotFoundException(std::string filename) : Exception() {
65  setMessage("Could not open the file " + filename);
66  };
68  FileNotFoundException(int line, const char * file) : Exception(line,file) {};
69  FileNotFoundException(std::string message, int line, const char * file): Exception(message,line,file) {};
70 };
71 
72 class FAST_EXPORT OutOfBoundsException : public Exception {
73  public:
75  setMessage("Out of bounds.");
76  };
77  OutOfBoundsException(int line, const char * file) : Exception(line,file) {
78  setMessage("Out of bounds.");
79  };
80  OutOfBoundsException(std::string message, int line, const char * file): Exception(message,line,file) {};
81 };
82 
83 class FAST_EXPORT NotImplementedException : public Exception {
84  public:
86  setMessage("Not implemented");
87  };
88  NotImplementedException(int line, const char * file) : Exception(line,file) {
89  setMessage("Not implemented");
90 
91  };
92 };
93 
94 class FAST_EXPORT DoesNotExistException : public Exception {
95  public:
96  DoesNotExistException(std::string msg) : Exception(msg) {};
97 };
98 
99 class FAST_EXPORT ExistException : public Exception {
100  public:
101  ExistException(std::string msg) : Exception(msg) {};
102 
103 };
104 
105 class FAST_EXPORT BadCastException : public Exception {
106  public:
107  BadCastException(std::string from, std::string to) : Exception("Bad cast. Tried to cast from type " + from + " to " + to) {};
108 };
109 
110 class FAST_EXPORT ThreadStopped : public Exception {
111  public:
113  setMessage("Thread stopped!");
114  }
115 };
116 
117 } // end namespace fast
118 
119 
120 #endif /* EXCEPTIONS_HPP_ */
fast::OutOfBoundsException
Definition: Exception.hpp:72
fast::ThreadStopped
Definition: Exception.hpp:110
fast::Exception::Exception
Exception(std::string message, int line, const char *file)
Definition: Exception.hpp:32
fast::NotImplementedException::NotImplementedException
NotImplementedException(int line, const char *file)
Definition: Exception.hpp:88
fast::Exception::~Exception
~Exception()
Definition: Exception.hpp:55
fast::BadCastException
Definition: Exception.hpp:105
fast::Exception
Definition: Exception.hpp:15
fast::DoesNotExistException
Definition: Exception.hpp:94
fast::ExistException
Definition: Exception.hpp:99
fast
Definition: AffineTransformation.hpp:7
fast::DoesNotExistException::DoesNotExistException
DoesNotExistException(std::string msg)
Definition: Exception.hpp:96
fast::ExistException::ExistException
ExistException(std::string msg)
Definition: Exception.hpp:101
fast::Exception::what
virtual const char * what() const
Definition: Exception.hpp:37
fast::NotImplementedException::NotImplementedException
NotImplementedException()
Definition: Exception.hpp:85
fast::FileNotFoundException
Definition: Exception.hpp:62
fast::BadCastException::BadCastException
BadCastException(std::string from, std::string to)
Definition: Exception.hpp:107
fast::FileNotFoundException::FileNotFoundException
FileNotFoundException(std::string filename)
Definition: Exception.hpp:64
fast::FileNotFoundException::FileNotFoundException
FileNotFoundException()
Definition: Exception.hpp:67
fast::Exception::setLine
void setLine(int line)
Definition: Exception.hpp:46
fast::Exception::Exception
Exception(int line, const char *file)
Definition: Exception.hpp:27
fast::FileNotFoundException::FileNotFoundException
FileNotFoundException(int line, const char *file)
Definition: Exception.hpp:68
fast::Exception::setMessage
void setMessage(std::string message)
Definition: Exception.hpp:52
fast::ThreadStopped::ThreadStopped
ThreadStopped()
Definition: Exception.hpp:112
fast::OutOfBoundsException::OutOfBoundsException
OutOfBoundsException()
Definition: Exception.hpp:74
fast::OutOfBoundsException::OutOfBoundsException
OutOfBoundsException(std::string message, int line, const char *file)
Definition: Exception.hpp:80
fast::Exception::Exception
Exception(std::string message)
Definition: Exception.hpp:22
fast::Exception::Exception
Exception()
Definition: Exception.hpp:17
fast::OutOfBoundsException::OutOfBoundsException
OutOfBoundsException(int line, const char *file)
Definition: Exception.hpp:77
fast::FileNotFoundException::FileNotFoundException
FileNotFoundException(std::string message, int line, const char *file)
Definition: Exception.hpp:69
fast::Exception::setFile
void setFile(const char *file)
Definition: Exception.hpp:49
fast::NotImplementedException
Definition: Exception.hpp:83
fast::intToString
std::string intToString(int number)
Definition: Exception.hpp:10