public member function

std::error_code::message

<system_error>
string message() const;
Get message
Returns the message associated with the error code.

Error messages are defined by the category the error code belongs to.

This function returns the same as if the following member was called:
 
category().message(value())


Parameters

none

Return value

A string object with the message associated with the error code.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// error_code observers: value, category and message
#include <iostream>
#include <system_error>
#include <fstream>
#include <string>

int main()
{
  std::ifstream is;
  is.exceptions (std::ios::failbit);
  try {
    is.open ("unexistent.txt");
  } catch (std::system_error e) {
    std::cout << "Exception caught (system_error): " << std::endl;
    std::cout << "Error: " << e.what() << std::endl;
    std::cout << "Code: " << e.code().value() << std::endl;
    std::cout << "Category: " << e.code().category().name() << std::endl;
    std::cout << "Message: " << e.code().message() << std::endl;
  }
}


Possible output:
Exception caught (system_error):
Error: ios_base::failbit set
Code: 1
Category: iostream
Message: iostream stream error

See also