I have written a Linux daemon in C++. The code is something like this:
int main(int argc, char** argv)
{
daemon(1, 0); // Daemonize itself, retaining the current working directory and redirecting stdin, stdout and stderr to /dev/null.
// My program logic goes here
}
The problem is, my program logic throws exceptions occasionally. How do I catch the exceptions so that I can know where goes wrong?
I know that for a plain console application, the uncaught exception will be dumped to the console. In my case, after calling daemon(1, 0), the console is no longer accessible.
On Windows, any uncaught exceptions will be saved by the OS, and can be viewed via the Event Viewer in Computer Management. Is there a similar mechanism on Linux?