E
Ed Dana
I am attempting to use exception handling in the console to trap an
invalid character into a numeric field. Unfortunately, using this example:
======================================================================
#include <exception>
#include <iostream>
using namespace std;
int main(int argc, char *argv[]) {
double number = 0;
while (number <= 0) {
std::cout << "Gimme a number: ";
try {
std::cin >> number;
}
catch (exception e) {
std::cout << "Oops, you did it again.";
}
}
}
======================================================================
all I get is an endless loop. What exception should I be using and what
header file if not above. Any clues appreciated.
invalid character into a numeric field. Unfortunately, using this example:
======================================================================
#include <exception>
#include <iostream>
using namespace std;
int main(int argc, char *argv[]) {
double number = 0;
while (number <= 0) {
std::cout << "Gimme a number: ";
try {
std::cin >> number;
}
catch (exception e) {
std::cout << "Oops, you did it again.";
}
}
}
======================================================================
all I get is an endless loop. What exception should I be using and what
header file if not above. Any clues appreciated.