24 #pragma warning(disable : 4668)
25 #define WIN32_LEAN_AND_MEAN
28 #if defined(MessageBox)
59 if(0 == m_code) { m_what = m_message; }
60 else { m_what =
"error " + std::to_string(m_code) +
": " + m_message; }
77 m_error =
static_cast<std::int64_t
>(GetLastError());
90 wchar_t* ptr{
nullptr};
91 const DWORD cchMsg{FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_ALLOCATE_BUFFER,
nullptr,
static_cast<uint32_t
>(
code()), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
reinterpret_cast<wchar_t*
>(&ptr), 0,
nullptr)};
94 auto deleter = [](
void* p)
96 if(p !=
nullptr) { ::LocalFree(p); }
98 std::unique_ptr<wchar_t,
decltype(deleter)> ptrBuffer(ptr, deleter);
100 if(ret.size() >= 2 && ret[ret.size() - 1] ==
'\n' && ret[ret.size() - 2] ==
'\r') ret.erase(ret.size() - 2);
103 else {
throw Term::Exception(::GetLastError(),
"Error in FormatMessageW"); }
108 std::string what{std::string(
"windows error ") + std::to_string(code()) + std::string(
": ") + message().c_str()};
109 if(!context().empty()) what +=
" [" + context() +
"]";
140 int err{
static_cast<int>(m_errno)};
143 m_errno =
static_cast<std::uint32_t
>(errno);
145 m_check_value = {ret};
170 std::string what{
"errno " + std::to_string(code()) +
": " + message()};
171 if(!context().empty()) { what += +
" [" + context() +
"]"; }
179 std::exception_ptr exception{std::current_exception()};
180 if(exception !=
nullptr) { std::rethrow_exception(exception); }
201 catch(
const std::exception& exception)
238 (void)(std::fflush(stderr));
const char * what() const noexcept override
virtual void build_what() const noexcept
void setContext(const std::string &context) noexcept
void setWhat(const std::string &what) const noexcept
static const constexpr std::size_t m_maxSize
Exception(const std::string &message) noexcept
void setMessage(const std::string &message) noexcept
std::string message() const noexcept
std::string context() const noexcept
std::int64_t code() const noexcept
void build_what() const noexcept final
ErrnoException(const ErrnoException &)=default
void throw_exception(const std::string &str={}) const
bool check_value() const noexcept
std::int64_t error() const noexcept
virtual ~Errno() noexcept
Errno & check_if(const bool &ret) noexcept
bool check_value() const noexcept
WindowsError & check_if(const bool &ret) noexcept
std::int64_t error() const noexcept
void throw_exception(const std::string &str=std::string()) const
WindowsException(const std::int64_t &error, const std::string &context=std::string())
void build_what() const noexcept final
std::wstring to_wide(const std::string &str)
std::string to_narrow(const std::wstring &wstr)
void ExceptionHandler(const ExceptionDestination &destination=ExceptionDestination::StdErr) noexcept
std::string string() noexcept
String version of cpp-terminal.
std::uint16_t returnCode() noexcept