Skip to contentSkip to conversation

throw()...Clarification

DISCUSSION Anand Chug 1 participant 1 message May 16, 2005

lore
Share & tools
lore

Anand Chug

author
#0 lore raw

Hi

void f();
means that any type of exception may be thrown from the function. If you say void f() throw();
it means that no exceptions are thrown from a function

So suppose i write a code like this

#include<iostream>
using namespace std;

class A
{
public:

    A(int x1,int y1):x(x1),y(y1){} ;
    int calc () throw();

private:

    int x,y;
};

int A::calc ()

{
    int temp;
    temp=x-y;
    if(temp<0)
        throw 0;
    return temp;
}
int main()
{
    A a(4,5);
    try{
        a.calc ();
    }catch(...)
    {
        cout<<"Exception"<<endl;
    }
    return 0;
}

According to the definition of throw()
calc() function should not throw any exception.
But while executing the above code in am getting "Exception" as output.. Any ideas...???