Dune Core Modules (2.4.2)

Dune::ExceptionHook Struct Referenceabstract

Base class to add a hook to the Dune::Exception. More...

#include <dune/common/exceptions.hh>

Detailed Description

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

struct ExceptionHookDebugger : public Dune::ExceptionHook
{
char * process_;
char * debugger_;
ExceptionHookDebugger (int argc, char ** argv, std::string debugger)
{
process_ = strdup(argv[0]);
debugger_ = strdup(debugger.c_str());
}
virtual void operator () ()
{
pid_t pid = getpid();
pid_t cpid;
cpid = fork();
if (cpid == 0) // child
{
char * argv[4];
argv[0] = debugger_;
argv[1] = process_;
argv[2] = new char[12];
snprintf(argv[2], 12, "%i", int(pid));
argv[3] = 0;
// execute debugger
std::cout << process_ << "\n";
std::cout << argv[0] << " "
<< argv[1] << " "
<< argv[2] << std::endl;
execv(argv[0], argv);
}
else // parent
{
// send application to sleep
kill(pid, SIGSTOP);
}
}
};
Base class to add a hook to the Dune::Exception.
Definition: exceptions.hh:169

This hook is registered via a static method of Dune::Exception:

int main(int argc, char** argv) {
Dune::MPIHelper & mpihelper = Dune::MPIHelper::instance(argc,argv);
ExceptionHookDebugger debugger(argc, argv, "/usr/bin/ddd");
try
{
...
}
catch (std::string & s) {
std::cout << mpihelper.rank() << ": ERROR: " << s << std::endl;
}
catch (Dune::Exception & e) {
std::cout << mpihelper.rank() << ": DUNE ERROR: " << e.what() << std::endl;
}
}
Base class for Dune-Exceptions.
Definition: exceptions.hh:91
A real mpi helper.
Definition: mpihelper.hh:160
int rank() const
return rank of process
Definition: mpihelper.hh:227
static DUNE_EXPORT MPIHelper & instance(int &argc, char **&argv)
Get the singleton instance of the helper.
Definition: mpihelper.hh:217
static void registerHook(ExceptionHook *hook)
add a functor which is called before a Dune::Exception is emitted (see Dune::ExceptionHook)
Definition: exceptions.hh:184
const std::string & what() const
output internal message buffer
Definition: exceptions.hh:199

The documentation for this struct was generated from the following file:
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (Apr 19, 22:31, 2024)