Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
system_error Class Reference

#include <format.h>

Inheritance diagram for system_error:

Public Member Functions

template<typename... Args>
 system_error (int error_code, string_view message, const Args &...args)
 
int error_code () const
 

Protected Member Functions

 system_error ()
 

Protected Attributes

int error_code_
 

Private Member Functions

FMT_API void init (int err_code, string_view format_str, format_args args)
 

Detailed Description

An error returned by an operating system or a language runtime, for example a file opening error.

Definition at line 2198 of file format.h.

Constructor & Destructor Documentation

system_error::system_error ( )
inlineprotected

Definition at line 2205 of file format.h.

2205 : std::runtime_error("") {}
template<typename... Args>
system_error::system_error ( int  error_code,
string_view  message,
const Args &...  args 
)
inline

Constructs a :class:fmt::system_error object with a description formatted with fmt::format_system_error. message and additional arguments passed into the constructor are formatted similarly to fmt::format.

Example**::

This throws a system_error 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::system_error(errno, "cannot open file '{}'", filename);

Definition at line 2227 of file format.h.

2228  : std::runtime_error("") {
2229  init(error_code, message, make_format_args(args...));
2230  }
FMT_API void init(int err_code, string_view format_str, format_args args)
Definition: format-inl.h:234
const S const Args & args
Definition: format.h:3342
format_arg_store< Context, Args... > make_format_args(const Args &...args)
Definition: core.h:1199

Member Function Documentation

int system_error::error_code ( ) const
inline

Definition at line 2232 of file format.h.

2232 { return error_code_; }
int error_code_
Definition: format.h:2203
FMT_FUNC void system_error::init ( int  err_code,
string_view  format_str,
format_args  args 
)
private

Definition at line 234 of file format-inl.h.

235  {
236  error_code_ = err_code;
238  format_system_error(buffer, err_code, vformat(format_str, args));
239  std::runtime_error &base = *this;
240  base = std::runtime_error(to_string(buffer));
241 }
FMT_FUNC void format_system_error(internal::buffer &out, int error_code, string_view message) FMT_NOEXCEPT
Definition: format-inl.h:906
internal::basic_buffer< FMT_CHAR(S)> buffer
Definition: printf.h:757
std::basic_string< Char > vformat(basic_string_view< Char > format_str, basic_format_args< typename buffer_context< Char >::type > args)
Definition: format.h:3410
int error_code_
Definition: format.h:2203
std::string to_string(ModuleType const mt)
Definition: ModuleType.h:34

Member Data Documentation

int system_error::error_code_
protected

Definition at line 2203 of file format.h.


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