How do you throw a `std::value_error` exception in C++?

Responsive Ad Header

Question

Grade: Education Subject: Support
How do you throw a `std::value_error` exception in C++?
Asked by:
55 Viewed 55 Answers

Answer (55)

Best Answer
(319)
You can throw a `std::value_error` exception using the `throw` keyword followed by a `std::value_error` object. For example: `throw std::value_error("Invalid input value");`. You'll need to `#include ` to use this exception class. The string passed to the constructor provides a descriptive error message.