Hello,
I have a program where I am calculating a number and then taking the inverse of it (i.e: 1/x), I am going through this calculation many times...but there are times when x=0, which will make it not possible to take the invese of(i.e 1/0)......I am attempting to use a try /catch/throw method....my function's name is solver, and it is being called in main:
int main(){
try { solver(); }
}
now the function:
void solver(){
//this is where my ? is, I just need to check is if x == 0??
if (x == 0){
//is this exception, or do I write invalid_argument or range_error
//or is it basically anything I want it to be, are they biult in?
throw_exception("x found to be 0"
}
//now back to main
int main() {
try { solver(); }
catch(exception ){
cout<<"error, 0 calculated<<endl;}//end catch
}
I am getting a many errors with this...and since I've never used try/catch/throw...I am not sure what I am doing wrong...
also, when it does catch an exception, does it exit the program?
or is there a way to catch the exception and go to the next iteration and next calculation?? thanks for any help...