I am working on a system that is designed to use classes error_code, error_conditionand error_categoryis a new std scheme: in C ++ 11, altoo at the moment I'm actually using the Boost implementation. I have read Chris Kholkoff a series of articles three times now, and I think I understand how to create these classes in general.
My problem is that this system needs to handle plugins that exist in separate DLLs, and plugins can create errors. In my original design, I developed one systematic category of errors that would cover all of the various error codes and a short list of specific error conditions that do not actually correspond to the values errno. The problem is that in order for the DLL to use one of these error codes, it needs access to a single instance error_categoryin the application. I am processing this now, exporting a function SetErrorCategory()from every DLL that works, but is ridiculous.
An alternative solution that I see is that each DLL has its own category of errors and codes and, if necessary, its own conditions; I suspect that this is more like what was provided for this library. But, I think, this requires a comparison function in the main application error scheme, which knows about plugin error schemes and can check which of the application conditions corresponds to the plugin error. This seems even more prone to many problems, although I have not yet tried to implement it. I assume that I will have to export the entire error scheme from the DLL, on top of all the real logic.
Another way to do this, of course, is to simply use numeric error codes from the DLL and include them in the error objects on the application side. This has the advantage of simplicity for the plugin, but can lead to gotchas in the application (for example, the function of juggling objects from a pair of different plugins should pay attention to the source of each error).
So, my specific question: of the three options that you would use, and why? What is clearly inoperative? And of course, is there a better way that hasnβt come to me?
source
share