Skip to content
View in the app

A better way to browse. Learn more.

Tip.It Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

A simple exception problem in c++

Featured Replies

#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 identifier

1>.\Customexception.cpp(59) : error C2228: left of '.what' must have class/struct/union

1> type is ''unknown-type''

1>.\Customexception.cpp(60) : error C2228: left of '.getNonIntegerData' must have class/struct/union

1> 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

Important Information

By using this site, you agree to our Terms of Use.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.