LD220
Jun 9, 2009, 01:45 PM
Hi guys. This forum really helped me out last time and I'm hoping you'll be able to again. Like I said in my last thread, I'm new to C++ and using the book 'SAMS Teach Yourself C++ in 10 Minutes" to try to learn on my own. I'm in Lesson 11 and it wants me to throw an exception. I've added the #include <exception> line to the top of my file and using namespace std; was already in there. In main() I use this catch statement (straight from book)
catch (runtime_error RuntimeError)
{
SAMSErrorHandling::HandleRuntimeError(RuntimeError);
}
This is in my Accumulator() function
default:
throw
runtime_error
("Error - Invalid operator");
break;
and this is in my ErrorHandling module
int HandleRuntimeError(runtime_error theRuntimeError)
{
cerr <<
theRuntimeError.what() <<
endl;
return 1;
}
I've uploaded the files as .txt, so it might be easier to help (the header is renamed since before it was .h and it didn't complain about me having 2 files that are the same). I keep getting a ton of errors. Here's what I got when I tried g++ ErrorHandlingModule.cpp PromptModule.cpp main.cpp
ErrorHandlingModule.cpp:27: error: ‘runtime_error’ was not declared in this scope
ErrorHandlingModule.cpp:28: error: expected ‘,’ or ‘;’ before ‘{’ token
main.cpp:2: error: expected constructor, destructor, or type conversion before ‘<’ token
main.cpp: In function ‘float Accumulate(char, float)’:
main.cpp:41: error: ‘runtime_error’ was not declared in this scope
main.cpp: In function ‘int main(int, char**)’:
main.cpp:61: error: expected type-specifier before ‘runtime_error’
main.cpp:61: error: expected `)' before ‘RuntimeError’
main.cpp:61: error: expected `{' before ‘RuntimeError’
main.cpp:61: error: ‘RuntimeError’ was not declared in this scope
main.cpp:61: error: expected `;' before ‘)’ token
main.cpp:65: error: expected primary-expression before ‘catch’
main.cpp:65: error: expected `;' before ‘catch’
main.cpp:70: error: ‘SAMSPrompt’ has not been declared
main.cpp:70: error: ‘UserWantsToContinueYOrN’ was not declared in this scope
main.cpp:73: error: expected `while' at end of input
main.cpp:73: error: expected `(' at end of input
main.cpp:73: error: expected primary-expression at end of input
main.cpp:73: error: expected `)' at end of input
main.cpp:73: error: expected `;' at end of input
main.cpp:73: error: expected `}' at end of input
Does anyone have any idea what's going wrong? Sorry for the really long post.
catch (runtime_error RuntimeError)
{
SAMSErrorHandling::HandleRuntimeError(RuntimeError);
}
This is in my Accumulator() function
default:
throw
runtime_error
("Error - Invalid operator");
break;
and this is in my ErrorHandling module
int HandleRuntimeError(runtime_error theRuntimeError)
{
cerr <<
theRuntimeError.what() <<
endl;
return 1;
}
I've uploaded the files as .txt, so it might be easier to help (the header is renamed since before it was .h and it didn't complain about me having 2 files that are the same). I keep getting a ton of errors. Here's what I got when I tried g++ ErrorHandlingModule.cpp PromptModule.cpp main.cpp
ErrorHandlingModule.cpp:27: error: ‘runtime_error’ was not declared in this scope
ErrorHandlingModule.cpp:28: error: expected ‘,’ or ‘;’ before ‘{’ token
main.cpp:2: error: expected constructor, destructor, or type conversion before ‘<’ token
main.cpp: In function ‘float Accumulate(char, float)’:
main.cpp:41: error: ‘runtime_error’ was not declared in this scope
main.cpp: In function ‘int main(int, char**)’:
main.cpp:61: error: expected type-specifier before ‘runtime_error’
main.cpp:61: error: expected `)' before ‘RuntimeError’
main.cpp:61: error: expected `{' before ‘RuntimeError’
main.cpp:61: error: ‘RuntimeError’ was not declared in this scope
main.cpp:61: error: expected `;' before ‘)’ token
main.cpp:65: error: expected primary-expression before ‘catch’
main.cpp:65: error: expected `;' before ‘catch’
main.cpp:70: error: ‘SAMSPrompt’ has not been declared
main.cpp:70: error: ‘UserWantsToContinueYOrN’ was not declared in this scope
main.cpp:73: error: expected `while' at end of input
main.cpp:73: error: expected `(' at end of input
main.cpp:73: error: expected primary-expression at end of input
main.cpp:73: error: expected `)' at end of input
main.cpp:73: error: expected `;' at end of input
main.cpp:73: error: expected `}' at end of input
Does anyone have any idea what's going wrong? Sorry for the really long post.
