Reputation: 5
Can anyone help me about this? The compiler doesn't recognize the exception e but how I should declare it? The application simply should divide two numbers throwing an exception if the second is 0.
#include <iostream>
#include <exception>
using namespace std;
float divide(float, float) throw(exception);
int main(int argc, char** argv) {
float a,b;
float c=0;
cin>>a;
cin>>b;
try{
c=divide(a,b);
}
catch(Exception e){
cout<<"You cannot do this";
};
return 0;
}
float divide(float a, float b) throw(exception) {
float c=a/b;
if(b==0)
throw Exception &e;
return c;
}
Upvotes: 1
Views: 636
Reputation: 385325
Well, you tried to use a class Exception
but never declared it. So it does not exist.
You could use one of the standard exception types. In fact, it looks like you may be attempting to use the base class std::exception
: that's a lower-case e
.
I suggest std::runtime_error
from <stdexcept>
, instead.
Upvotes: 1