I apologize in advance for a somewhat vague question, which may have, perhaps, several answers, but nevertheless, the practical aspect is of primary interest.
So, there is a certain not very large project consisting of a number of independent modules, each completely independent of itself and written by different people at different times.
Often in the code I see different (which is natural, imho) error catching options, from quite suitable and relevant to just try{...} catch{MessageBox.Show("Ошибка!");} (Yes, and this does not happen), often critical places without any try blocks.
The task is to bring this business (error handling) to a standard, at least within the framework of this project, and then the fun begins - in many places there are repetitive operations, for example, when working with files and directories, and in such places you often have to either write, or already have constructions of the form:
if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException(path, "Путь к каталогу должен быть задан."); } Or there are similar constructions where, in the event of an error situation, an exception of some type is raised (for example, IOException ) with some textual description. At the same time, there is no (almost no, honestly) inside the project any sort of class hierarchy for error handling, standard errors are used mainly.
So, initially the view on the general infrastructure of error handling and the approach as a whole was interesting. But this aspect has already clarified for itself.
But for the time being I don’t really understand what would be the best approach with the generation of error text messages both for the modules of the project itself and for the logger? (used logger, able to work with Exception instances).
So far the first thing that came to mind is to put all the messages in a separate file in the form of constants and use them by connecting the file to each of the modules. Or maybe drive all the resources?
But in general, community views are interesting, what other practical implementations and approaches, techniques would be appropriate and convenient in everyday use, taking into account the described context? Perhaps there are some more effective, convenient and proven methods or means?
PS
- Localization of the project into several languages - not yet.
- It would not be very desirable to make significant changes to the code of the modules (one would have to manage with a little blood).
- I would like to avoid third-party solutions if, of course, they do not solve the problem systematically and are applicable in the future (I remembered EurekaLog in Delphi).
Thank you for your attention to the question!