cpp-terminal 1.0.0
Small C++ library for writing multiplatform terminal applications
Loading...
Searching...
No Matches
Term::Private::WindowsException Class Reference

#include <cpp-terminal/private/exception.hpp>

Inheritance diagram for Term::Private::WindowsException:
Term::Exception

Public Member Functions

 WindowsException (const std::int64_t &error, const std::string &context=std::string())
 
 ~WindowsException () override=default
 
- Public Member Functions inherited from Term::Exception
 Exception (const std::string &message) noexcept
 
 Exception (const std::int64_t &code, const std::string &message) noexcept
 
 Exception (const Exception &)=default
 
 Exception (Exception &&)=default
 
Exceptionoperator= (Exception &&)=default
 
Exceptionoperator= (const Exception &)=default
 
const char * what () const noexcept override
 
std::int64_t code () const noexcept
 
std::string message () const noexcept
 
std::string context () const noexcept
 
 ~Exception () noexcept override=default
 

Private Member Functions

void build_what () const noexcept final
 

Additional Inherited Members

- Protected Member Functions inherited from Term::Exception
 Exception (const std::int64_t &code) noexcept
 
void setMessage (const std::string &message) noexcept
 
void setContext (const std::string &context) noexcept
 
void setWhat (const std::string &what) const noexcept
 
- Static Protected Attributes inherited from Term::Exception
static const constexpr std::size_t m_maxSize {256}
 

Detailed Description

Definition at line 43 of file exception.hpp.

Constructor & Destructor Documentation

◆ WindowsException()

Term::Private::WindowsException::WindowsException ( const std::int64_t & error,
const std::string & context = std::string() )

Definition at line 87 of file exception.cpp.

87 : Term::Exception(static_cast<std::int64_t>(error))
88{
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)};
92 if(cchMsg > 0)
93 {
94 auto deleter = [](void* p)
95 {
96 if(p != nullptr) { ::LocalFree(p); }
97 };
98 std::unique_ptr<wchar_t, decltype(deleter)> ptrBuffer(ptr, deleter);
99 std::string ret{Term::Private::to_narrow(ptrBuffer.get())};
100 if(ret.size() >= 2 && ret[ret.size() - 1] == '\n' && ret[ret.size() - 2] == '\r') ret.erase(ret.size() - 2);
101 setMessage(ret);
102 }
103 else { throw Term::Exception(::GetLastError(), "Error in FormatMessageW"); }
104}
void setContext(const std::string &context) noexcept
Definition exception.cpp:65
void setMessage(const std::string &message) noexcept
Definition exception.cpp:63
std::string context() const noexcept
Definition exception.cpp:53
std::int64_t code() const noexcept
Definition exception.cpp:49
std::string to_narrow(const std::wstring &wstr)
Definition unicode.cpp:26

◆ ~WindowsException()

Term::Private::WindowsException::~WindowsException ( )
overridedefault

Member Function Documentation

◆ build_what()

void Term::Private::WindowsException::build_what ( ) const
finalprivatevirtualnoexcept

Reimplemented from Term::Exception.

Definition at line 106 of file exception.cpp.

107{
108 std::string what{std::string("windows error ") + std::to_string(code()) + std::string(": ") + message().c_str()};
109 if(!context().empty()) what += " [" + context() + "]";
110 setWhat(what);
111}
const char * what() const noexcept override
Definition exception.cpp:43
void setWhat(const std::string &what) const noexcept
Definition exception.cpp:67
std::string message() const noexcept
Definition exception.cpp:51

The documentation for this class was generated from the following files: