Je les suivantes class exception
:manière correcte pour attraper une exception créée
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) {};
};
}
}
}
Et dans mon code que j'ai:
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?
}
Ma question est: comment vais-je attraper A: : B :: C :: internal_error? Dois-je utiliser:
catch(A::B::C::internal_error &error){
string msg("You should never had happened\n");
logmsg(MSERROR, msg.c_str(), who);
}
S'il vous plaît ignorer les balises MSERROR
, who
, mkdirpath
... ils ne sont pas importants à la question.
Est-ce que ce code ne fonctionne pas? – robert
Supprimer le _ avant internal_error, de sorte qu'il devient A :: B :: C :: internal_error – fbafelipe
J'ai supprimé ... ma question est: est-ce que je le fais correctement? – cybertextron