RunTime Error not working....

Hey guys,I was writing a sample program that uses the try and catch block(actually I was trying to learn).Having written the try block and catch block and completing the program, I tried to compile it.Here's the code...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
  #include<iostream>
#include<exception>
using namespace std;
int main()
{
    int a,b;
    float c;
    cout<<"Enter the nos."<<endl;
    while(cin>>a>>b)
    {
        try{
        c=a/b;
        cout<<"The result is = "<<c<<endl;
        }
        catch(runtime_error err )
        {
            cerr<<err.what()<<endl<<"Do you wanna try again? Y/N "<<endl;
            char c;
            cin>>c;
            if(!cin||c=='N'||c=='n')
                break;
        }
    }

}


Sorry if I did something wrong in the post, Im a newbie here....
But when I compile this code in Code::Blocks 13.12, it says something like "error: expected type specifier before runtime_error" and things like a '(' and '}' before and after 'err'.
So I got here,saw through the exception tutorial and changed the code like this

catch(exception& err )

What I dont understand is why did the compiler didnt accept the runtime_error and what is a type specifier(sorry, Im a newbie,maybe its int or float).
And what happened when I used 'exception' in the program ? Is there something I missed??

I was reading the C++ Primer and came here when I had a problem.I accept every kind of view...pls give a reply as I dont get the problem...
Yours friendly newbie,
LadyInRed7.
#include<stdexcept>

See:
http://www.cplusplus.com/reference/stdexcept/runtime_error/?kw=runtime_error

By the way: 'divide by zero' does not throw a standard exception.
Last edited on
Topic archived. No new replies allowed.