I am trying to use an external C++
library which have defined its exceptions as:
enum MY_ERRORS {
ERR_NONE = 0,
ERR_T1,
ERR_T2,
};
Then in the code exceptions are thrown like this:
if(...) {
throw ERR_T1;
Being new to programming in C++, I would do something like:
try {
call_to_external_library();
} catch(??? err) {
printf("An error occurred: %s\n", err);
} catch(...) {
printf("An unexpected exception occurred.\n");
}
How do I determine what was thrown?
You will need to write your code to handle the type of enumeration in the catch block:
try {
call_to_external_library();
} catch(MY_ERRORS err) { // <------------------------ HERE
printf("An error occurred: %s\n", err);
} catch(...) {
printf("An unexpected exception occurred.\n");
}
You must catch the type MY_ERRORS
and then compare against the possible values
try {
call_to_external_library();
} catch(MY_ERRORS err) {
printf("An error occurred: %s\n", err);
} catch(...) {
printf("An unexpected exception occurred.\n");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With