# Provide one file where all error messages are defined in c++ [closed]

I would like to store all error messages in one file and call them for example with

if (!std::filesystem::exists(ArgFilename)) {
throw std::runtime_error{error_001_nofile};
} else {
//do something
}


The file errorcodes.h is included to the main program and looks like

#ifndef SRC_ERRORCODES_H_
#define SRC_ERRORCODES_H_
#include <string_view>

constexpr char error_002_nomem[] = "Error 002: Not enough memory.";
#endif /* SRC_ERRORCODES_H_ */


Cevelop warns, that constexpr char is no proper c++, but c code. Is there a clean c++ solution to manage error messages?

• const should be enough if there's nothing to evaluate. – πάντα ῥεῖ Nov 14 '19 at 21:46
• Why did someone down vote? What can I improve in the question? – Jonas Stein Nov 14 '19 at 22:25
• @πάνταῥεῖ Thank you. Will change that here, but I leave the question as is for the reader. – Jonas Stein Nov 14 '19 at 22:26
• There's nothing wrong with using C-string constants in C++. I would write char const* name = "value";, but I think in the end it's the same. – Cris Luengo Nov 14 '19 at 23:29

constexpr is probably overkill, but not in any way wrong.
constexpr char error_001_nofile[]{"Error 001: File not found."};

or using a std::string:
constexpr std::string error_001_nofile{"Error 001: File not found."};