Yello.
Quick question regarding re-throwing an exception.
Many examples of re-throwing exceptions use code similar to that below. But they do NOT explain exactly why you want to do it.
This code terminates the program with a debug error dialogue message from MSVC. Now, normally you probably wont rethrow from these circumstances - but this is similar to the simple examples found on the web and in books. Is the idea to terminate execution of the program at this point or what?
Cheers
FB
Code:#include <iostream> using namespace std; class CError { private: const char * error; public: CError(const char * e) { error = e; } void output() { cout << error << endl; } }; void check(int num) { if (num < 0) throw CError("Negative Number"); } int main(void) { int x; try { // Enter a negative number to // throw the exception cout << "Enter a positive number: " << flush; cin >> x; check(x); } catch(CError & e) { e.output(); throw; // Rethrow the exception } return 0; }