CFileTask, CFileApprise and exceptions.

Both these classes can generate exceptions that if created are passed up the call chain without any internal catch clauses; with the exception of an error 22 which can be generated by inotify_rm_watch() while removing a watch but is valid behavior and processing is allowed to continue.

But both classes processing loops CFileTask::monitor() and CFileApprise:watch() are designed to run as a separate thread so  any exceptions caught inside these are lost to the main code although they could be reported via a suitable error message.

To make sure that any exceptions generated  are passed to the main code each class has a variable  std::exception_ptr thrownException that is used to store the current exception when one is generated and the looping function exiting the thread. To check if any where generated the caller uses class method getThrownException() which is non null if the reason for exit was an exception. The caller can then do whatever they require with it which in the case of the FPE is re-throw so it is caught locally.

The CFileTask uses a CFileApprise object run on a separate thread so before it exits its main loop it checks CFileApprise::getThrownException() and if set then copies that value to its own thrownException (basically passing the thrown exception back up the call chain). Note that this mechanism does rely on the object instance staying in scope and not being destroyed. CFileApprise also will generate an event for an exception which may be picked by the callers event loop and dealt with as appropriate.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s