Base class to add a hook to the Dune::Exception.
The user can add a functor which should be called before a Dune::Exception is emitted.
Example: attach a debugger to the process, if an exception is thrown
{
char * process_;
char * debugger_;
ExceptionHookDebugger (int argc, char ** argv, std::string debugger)
{
process_ = strdup(argv[0]);
debugger_ = strdup(debugger.c_str());
}
{
pid_t pid = getpid();
pid_t cpid;
cpid = fork();
if (cpid == 0)
{
char * argv[4];
argv[0] = debugger_;
argv[1] = process_;
argv[2] = new char[12];
snprintf(argv[2], 12, "%i", int(pid));
argv[3] = 0;
std::cout << process_ << "\n";
std::cout << argv[0] << " "
<< argv[1] << " "
<< argv[2] << std::endl;
execv(argv[0], argv);
}
else
{
kill(pid, SIGSTOP);
}
}
};
This hook is registered via a static method of Dune::Exception:
int main(int argc, char** argv) {
ExceptionHookDebugger debugger(argc, argv, "/usr/bin/ddd");
try
{
...
}
catch (std::string & s) {
std::cout << mpihelper.
rank() <<
": ERROR: " << s << std::endl;
}
std::cout << mpihelper.
rank() <<
": DUNE ERROR: " << e.
what() << std::endl;
}
}