The cpp std runtime_error is an exception class that represents a runtime error. It is a predefined class in the C++ Standard Library that is used to report errors that occur during program execution.
Example:
```c++
#include
#include
int main() {
int a, b;
std::cin >> a >> b;
try {
if(b == 0) {
throw std::runtime_error("Divide by zero error.");
}
std::cout << "a/b = " << a/b << std::endl;
}
catch(const std::runtime_error& e) {
std::cerr << "Runtime error: " << e.what() << std::endl;
}
return 0;
}
```
In the example above, the std runtime_error is used to handle a divide-by-zero error. If b is zero, the program throws a runtime error with the message "Divide by zero error." The catch statement catches the exception and prints the error message to the console.
The cpp std runtime_error is part of the C++ Standard Library, which is included in the standard C++ library package.
C++ (Cpp) std::runtime_error - 30 examples found. These are the top rated real world C++ (Cpp) examples of std::runtime_error extracted from open source projects. You can rate examples to help us improve the quality of examples.