Add errno_error exception type
Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
parent
ff8ca7f073
commit
515d92b035
77
include/stdex/errno.h
Normal file
77
include/stdex/errno.h
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
SPDX-License-Identifier: MIT
|
||||
Copyright © 2023 Amebis
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "sal.h"
|
||||
#include <stdexcept>
|
||||
#include <cstring>
|
||||
|
||||
namespace stdex
|
||||
{
|
||||
///
|
||||
/// Standard C runtime library error
|
||||
///
|
||||
class errno_error : public std::runtime_error
|
||||
{
|
||||
public:
|
||||
///
|
||||
/// Constructs an exception
|
||||
///
|
||||
/// \param[in] num Numeric error code
|
||||
/// \param[in] msg Error message
|
||||
///
|
||||
errno_error(_In_ errno_t num, _In_ const std::string& msg) :
|
||||
m_num(num),
|
||||
runtime_error(msg)
|
||||
{
|
||||
}
|
||||
|
||||
///
|
||||
/// Constructs an exception
|
||||
///
|
||||
/// \param[in] num Numeric error code
|
||||
/// \param[in] msg Error message
|
||||
///
|
||||
errno_error(_In_ errno_t num, _In_opt_z_ const char *msg = nullptr) :
|
||||
m_num(num),
|
||||
runtime_error(msg)
|
||||
{
|
||||
}
|
||||
|
||||
///
|
||||
/// Constructs an exception using `GetLastError()`
|
||||
///
|
||||
/// \param[in] msg Error message
|
||||
///
|
||||
errno_error(_In_ const std::string& msg) :
|
||||
m_num(errno),
|
||||
runtime_error(msg)
|
||||
{
|
||||
}
|
||||
|
||||
///
|
||||
/// Constructs an exception using `GetLastError()`
|
||||
///
|
||||
/// \param[in] msg Error message
|
||||
///
|
||||
errno_error(_In_opt_z_ const char *msg = nullptr) :
|
||||
m_num(errno),
|
||||
runtime_error(msg)
|
||||
{
|
||||
}
|
||||
|
||||
///
|
||||
/// Returns the error number
|
||||
///
|
||||
errno_t number() const
|
||||
{
|
||||
return m_num;
|
||||
}
|
||||
|
||||
protected:
|
||||
errno_t m_num; ///< Numeric error code
|
||||
};
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user