BoosterSeat  0.1
A C++ library that includes common utilities that are used in other projects.
exception.hpp
Go to the documentation of this file.
1 #ifndef EXCEPTION_HPP_
2 #define EXCEPTION_HPP_
3 
5 #include <stdexcept>
6 #include <string>
7 
8 namespace bst {
9 
10 enum class ErrorNumber {
16  UNSPECIFIED = 0, // Default value, just for backwards compatibility.
17 
18  // -- Filesystem
19 
24 
29 
34 
39 
45 
50 
55 
60 
65 
70 
75 
79  TIME_INVALID_TIME = 12,
80 
87 
91  PROCESS_TIMEOUT = 14,
92 
97 };
98 
99 class BoosterSeatException : public std::exception {
100 public:
101  BoosterSeatException(const std::string &message,
102  ErrorNumber error_number = ErrorNumber::UNSPECIFIED)
103  : error_number_enum_(error_number),
104  error_number_(template_tools::to_underlying(error_number)),
105  message_("BST Errno: " + std::to_string(error_number_) + " | " +
106  message) {
107  }
109 
110  const char *what() const noexcept override {
111  return message_.c_str();
112  }
113 
114  ErrorNumber errorNumberEnum() const noexcept {
115  return error_number_enum_;
116  }
117 
118  int errorNumber() const noexcept {
119  return error_number_;
120  }
121 
122 private:
125  std::string message_;
126 };
127 
128 } // namespace bst
129 
130 #endif // BOOST_ERSEAT_HPP_
Definition: exception.hpp:99
int errorNumber() const noexcept
Definition: exception.hpp:118
ErrorNumber errorNumberEnum() const noexcept
Definition: exception.hpp:114
int error_number_
Definition: exception.hpp:124
std::string message_
Definition: exception.hpp:125
ErrorNumber error_number_enum_
Definition: exception.hpp:123
BoosterSeatException(const std::string &message, ErrorNumber error_number=ErrorNumber::UNSPECIFIED)
Definition: exception.hpp:101
const char * what() const noexcept override
Definition: exception.hpp:110
constexpr auto to_underlying(E e) noexcept
Converts an enum class to its underlying type.
Definition: template_tools.hpp:19
Definition: filesystem.cpp:34
ErrorNumber
Definition: exception.hpp:10
@ FS_NO_WRITE_PERMISSIONS
Throw if write permissions are required but do not exist.
@ PROCESS_TIMEOUT
Part of bst::Process, thrown if the process times out.
@ UNSPECIFIED
Default value, just for backwards compatibility. Should not be used in new code.
@ NOT_YET_IMPLEMENTED
Throws if a feature is not yet implemented.
@ PROCESS_NOT_COMPLETE
Part of bst::Process, thrown if the process is not yet complete yet a method is called that requires ...
@ FS_NO_READ_PERMISSIONS
Throw if read permissions are required but do not exist.
@ FS_PATH_NOT_REGULAR_FILE
Path is not a regular file. Includes path in message.
@ TIME_INVALID_TIME
Invalid time.
@ GEO_INVALID_LATITUDE
Latitude is out of range/invalid.
@ FS_PATH_ALREADY_EXISTS
Path already exists when it should not. Includes path in message.
@ FS_PATH_DOES_NOT_EXIST
Path does not exist when it should. Includes path in message.
@ FS_PATH_NOT_DIRECTORY
Path is not a directory. Includes path in message.
@ FS_INVALID_SIZE_UNIT
Thrown if an invalid size unit is used.
@ FS_FILE_NOT_VALID
File is not valid. Includes if/ofstream error code in message.
@ TIME_INVALID_TIMEZONE
Thrown if an invalid time zone is used.
@ GEO_INVALID_LONGITUDE
Longitude is out of range/invalid.