exception

hi everyone
i have a problem with this code
its run and show error text when i enter zero but if i again enter zero isnt work
i want to write a code like this and everytime i enter zero gets this code{ const ex error_zero("value is zero"); } without closing program.
thanks
my language is not english.
sorry about mistakes.

[code]

#include<iostream>
#include<cstdio>
#include<exception>
using namespace std;

class ex :public exception
{
const char* mas;
public:
ex(char const *mas)throw() :mas(mas) {}
char const *what()throw() { return mas; }

};
const ex error_zero("value is zero");

int get() {
int value;
cin >> value;
if (value == 0) {
throw error_zero;
}


return value;
}


int main() {
try {
get();


}
catch (ex & e)
{

cout << "ERROR : " << e.what() << endl;
get();

}



return 0;
}


[/ code]
i enter zero but if i again enter zero isnt work

In your catch block, you're calling get() again, but you're not within the range of a try block. Therefore, the catch handler won't be called again.

Please use code tags correctly. The closing code tag should NOT have a space in it.
[/code]

Last edited on
Topic archived. No new replies allowed.