unix_exception.hpp 963 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #pragma once
  2. #include <errno.h>
  3. #include <string.h>
  4. #include "../exception.hpp"
  5. namespace nkg::exceptions {
  6. class unix_exception : public ::nkg::exception {
  7. public:
  8. using error_code_t = decltype(errno);
  9. private:
  10. error_code_t m_error_code;
  11. std::string m_error_string;
  12. public:
  13. unix_exception(std::string_view file, int line, error_code_t unix_errno, std::string_view message) noexcept :
  14. ::nkg::exception(file, line, message), m_error_code(unix_errno), m_error_string(strerror(unix_errno)) {}
  15. [[nodiscard]]
  16. virtual bool error_code_exists() const noexcept override {
  17. return true;
  18. }
  19. [[nodiscard]]
  20. virtual intptr_t error_code() const noexcept override {
  21. return m_error_code;
  22. }
  23. [[nodiscard]]
  24. virtual const std::string& error_string() const noexcept override {
  25. return m_error_string;
  26. }
  27. };
  28. }