except.h 830 B

123456789101112131415161718192021222324252627282930
  1. #ifndef CORE_EXCEPT_H
  2. #define CORE_EXCEPT_H
  3. #include <exception>
  4. #include <string>
  5. #include <type_traits>
  6. namespace al {
  7. class base_exception : public std::exception {
  8. std::string mMessage;
  9. public:
  10. base_exception() = default;
  11. template<typename T, std::enable_if_t<std::is_constructible_v<std::string,T>,bool> = true>
  12. explicit base_exception(T&& msg) : mMessage{std::forward<T>(msg)} { }
  13. base_exception(const base_exception&) = default;
  14. base_exception(base_exception&&) = default;
  15. ~base_exception() override;
  16. auto operator=(const base_exception&) -> base_exception& = default;
  17. auto operator=(base_exception&&) -> base_exception& = default;
  18. [[nodiscard]] auto what() const noexcept -> const char* override { return mMessage.c_str(); }
  19. };
  20. } // namespace al
  21. #endif /* CORE_EXCEPT_H */