April 29, 201016 yr #include<iostream> #include<string> using namespace::std; class NonIntegerException : public runtime_error { private: string nonIntegerData; public: NonIntegerException(string); string getNonIntegerData(); }; NonIntegerException::NonIntegerException(string s) : runtime_error("Non-integer data") { nonIntegerData = s; } string NonIntegerException::getNonIntegerData() { return nonIntegerData; } int getInt(string prompt) { int integer; string badData; cout << prompt; if(!(cin >> integer)) { cin.clear(); cin >> badData; [b]NonIntegerException e(badData); throw e;[/b] } return integer; } int main() { int age; try { age = getInt("Enter your age "); } catch(NonIntegerException) { cout <<[b] e.what()[/b] << endl; cout << "The entered value was " <<[b] e.getNonIntegerData();[/b] cout << "Age is being set to 0" << endl; age = 0; } return 0; } The problem areas are bolded and also here are the errors that are popping up: 1>.\Customexception.cpp(59) : error C2065: 'e' : undeclared identifier1>.\Customexception.cpp(59) : error C2228: left of '.what' must have class/struct/union1> type is ''unknown-type''1>.\Customexception.cpp(60) : error C2228: left of '.getNonIntegerData' must have class/struct/union1> type is ''unknown-type''1>Build log was saved at "file://c:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\Customexception\Customexception\Debug\BuildLog.htm"1>Customexception - 3 error(s), 0 warning(s) The thing is here, I know that e is defined. Nevermind, Figured out that the problem was that I left out the "e" in the catch parentheses. The small stuff always throws you for a loop...... Quote - Revenge is such a nasty thing that only breeds more vengeful souls, but in some situations revenge does not even need to be sought out, but only bided.
Create an account or sign in to comment