Provide examples of using SystemError and WindowsError (#54)
This commit is contained in:
parent
48e6df117a
commit
f2c16957f7
39
format.h
39
format.h
@ -1404,10 +1404,23 @@ class SystemError : public internal::RuntimeError {
|
|||||||
/**
|
/**
|
||||||
\rst
|
\rst
|
||||||
Constructs a :class:`fmt::SystemError` object with the description
|
Constructs a :class:`fmt::SystemError` object with the description
|
||||||
of the form "*<message>*: *<system-message>*", where *<message>* is the
|
of the form
|
||||||
formatted message and *<system-message>* is the system message corresponding
|
|
||||||
to the error code.
|
.. parsed-literal::
|
||||||
|
*<message>*: *<system-message>*
|
||||||
|
where *<message>* is the formatted message and *<system-message>* is
|
||||||
|
the system message corresponding to the error code.
|
||||||
*error_code* is a system error code as given by ``errno``.
|
*error_code* is a system error code as given by ``errno``.
|
||||||
|
|
||||||
|
**Example**
|
||||||
|
|
||||||
|
// This throws a SystemError with the description
|
||||||
|
// cannot open file 'madeup': No such file or directory
|
||||||
|
// or similar (system message may vary).
|
||||||
|
const char *filename = "madeup";
|
||||||
|
std::FILE *file = std::fopen(filename, "r");
|
||||||
|
if (!file)
|
||||||
|
throw fmt::SystemError(errno, "cannot open file '{}'", filename);
|
||||||
\endrst
|
\endrst
|
||||||
*/
|
*/
|
||||||
SystemError(int error_code, StringRef message) {
|
SystemError(int error_code, StringRef message) {
|
||||||
@ -2091,10 +2104,24 @@ class WindowsError : public SystemError {
|
|||||||
/**
|
/**
|
||||||
\rst
|
\rst
|
||||||
Constructs a :class:`fmt::WindowsError` object with the description
|
Constructs a :class:`fmt::WindowsError` object with the description
|
||||||
of the form "*<message>*: *<system-message>*", where *<message>* is the
|
of the form
|
||||||
formatted message and *<system-message>* is the system message corresponding
|
|
||||||
to the error code.
|
.. parsed-literal::
|
||||||
|
*<message>*: *<system-message>*
|
||||||
|
where *<message>* is the formatted message and *<system-message>* is the system
|
||||||
|
message corresponding to the error code.
|
||||||
*error_code* is a Windows error code as given by ``GetLastError``.
|
*error_code* is a Windows error code as given by ``GetLastError``.
|
||||||
|
|
||||||
|
**Example**::
|
||||||
|
|
||||||
|
// This throws an WindowsError with the description
|
||||||
|
// cannot open file 'madeup': The system cannot find the file specified.
|
||||||
|
// or similar (system message may vary).
|
||||||
|
const char *filename = "madeup";
|
||||||
|
LPOFSTRUCT of = LPOFSTRUCT();
|
||||||
|
HFILE file = OpenFile(filename, &of, OF_READ);
|
||||||
|
if (file == HFILE_ERROR)
|
||||||
|
throw fmt::WindowsError(GetLastError(), "cannot open file '{}'", filename);
|
||||||
\endrst
|
\endrst
|
||||||
*/
|
*/
|
||||||
WindowsError(int error_code, StringRef message) {
|
WindowsError(int error_code, StringRef message) {
|
||||||
|
Loading…
Reference in New Issue
Block a user