-
exceptions
I have enum for errors for instance:
Code:
enum socket_errors {
ERR_UNRESOLVABLE = SOCKET_ERRORS,
ERR_INTERNAL,
ERR_SOCK_CREATION,
ERR_BIND_FAILED
};
And when I want to throw in some function this way:
Code:
void prevfunc() {
//stuff//
throw ERR_SOCK_CREATION;
return;
}
I cannot catch this way in some other function that is calling previous function:
Code:
try {
prevfunc();
}
catch (unsigned int) {
}
What would be the right way to catch it? What should I look for?
-
Try looking for socket_errors ?
-
Look for the enum, not uint.
Code:
int _tmain(int argc, TCHAR ** argv)
{
enum test { OH, MY, GOD };
try
{
throw GOD;
}
catch(enum test t)
{
std::cout << t << std::endl;
}
}
-
Throw class instances, they're less ambiguous about their type than primitives and enums.
-
In addition: http://www.parashift.com/c++-faq-lite/exceptions.html
You might want to pay special attention to 17.6 and 17.7