Reputation: 10971
I have the following class exception
:
namespace A{
namespace B{
namespace C{
class internal_error : public std::runtime_error{
public:
explicit internal_error(const std::string &arg) : std::runtime_error(arg) {};
};
}
}
}
And in my code I have:
try{
if(mkdipath(dirname, DIR_CREATION_MODE, &err)){
string msg;
msg = "failed to create path " + *dirname;
logmsg(MSERROR, msg.c_str(), who);
throw A::B::C::internal_error(msg);
}
}
catch(){
// how am I going to catch a A::B::C::internal_error?
}
My question is : how am I going to catch a A::B::C::internal_error? Should I use:
catch(A::B::C::internal_error &error){
string msg("You should never had happened\n");
logmsg(MSERROR, msg.c_str(), who);
}
Please ignore the tags MSERROR
, who
, mkdirpath
... they are not important to the question.
Upvotes: 0
Views: 100
Reputation: 930
try{
// ...
} catch (const A::internal_error& ex) {
// ...
} catch (const B::internal_error& ex) {
// ...
} catch (const C::internal_error& ex) {
// ...
}
Is this what you are looking for?
Upvotes: 0
Reputation: 13484
catch(A::B::C::internal_error &error){
//...
}
is fine, note sure where the leading underscore came from, probably a typo.
Upvotes: 1