Open spliffli opened 3 months ago
By the way, sorry for doing so many commits after I opened the pull request. It's because as I was editing the file in this repo directly on github, I improvised a new method to get the file name from a filepath so it can write that to the console when there's an exception, and I forgot to add the var keyword.
Feel free to edit the Console.WriteLine statements since I know you use a helper method called print for writing to the console.
Also, if you want me to instead open a different pull request on the developer branch instead of the main branch I can do that.
Updated the tryReadFile method so that it handles some exceptions and I ran into all 3 of these exceptions while building upon this code in another project and thought it might be worth contributing.
Because the tryReadFile method frequently gets called from a loop for checking for a file at a given path, returning an empty string after handling each exception means it will just try again at the next loop and operate smoothly without crashing the program.
DirectoryNotFoundException can happen when the MetaTrader EA either isn't running or isn't initialized properly, and it returns an empty string to continue the loop that's constantly checking a filepath until it either works or possibly it can be updated to infer the status of the EA as offline which could be useful.
FileNotFoundException was happening in my program even when the EA was running, and I found that by creating an empty file at location where it's expected to be fixes the problem, so it does that and returns an empty string.
IOException happens when more than one process accesses the same resource at the exact same time a.k.a. a race condition. This can be handled by just returning an empty string.