Error messages should be specific, descriptive, and include context to help with debugging. Avoid generic messages like "Failed execution" or numeric error codes without explanation.
Error messages should be specific, descriptive, and include context to help with debugging. Avoid generic messages like “Failed execution” or numeric error codes without explanation.
Key principles:
ShapeList::push_back: ShapeList limit exceeded
Expected type FLOAT32, but got INT32
Example with improved error messaging:
// Poor error message
if (size() <= idx || idx < 0)
throw std::runtime_error("Can't find requested variable by index");
// Better error message
if (size() <= idx || idx < 0)
throw std::runtime_error(
std::string("ShapeList::at: Index out of bounds, requested: ") +
std::to_string(idx) + " but size is: " + std::to_string(size())
);
For assertions in lower-level code that might be called from higher-level languages like Java, include descriptive messages that don’t require reading C++ code to understand the error condition.
Enter the URL of a public GitHub repository