mirror of
https://github.com/red0124/ssp.git
synced 2025-12-14 21:59:55 +01:00
Implement throw_on_error functionality, rename some template parameters
This commit is contained in:
30
include/ss/exception.hpp
Normal file
30
include/ss/exception.hpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
#include <exception>
|
||||
#include <string>
|
||||
|
||||
namespace ss {
|
||||
|
||||
////////////////
|
||||
// exception
|
||||
////////////////
|
||||
|
||||
class exception : public std::exception {
|
||||
std::string msg_;
|
||||
|
||||
public:
|
||||
exception(const std::string& msg): msg_{msg} {
|
||||
}
|
||||
|
||||
virtual char const* what() const noexcept {
|
||||
return msg_.c_str();
|
||||
}
|
||||
};
|
||||
|
||||
template <bool throw_on_error>
|
||||
void throw_if_throw_on_error(const std::string& msg) {
|
||||
if constexpr (throw_on_error) {
|
||||
throw ss::exception(msg);
|
||||
}
|
||||
}
|
||||
|
||||
} /* ss */
|
||||
Reference in New Issue
Block a user