I know it sounds weird but I am required to put a wrapping try catch block to every method to catch all exceptions. We have thousands of methods and I need to do it in an automated way. What do you suggest?
I am planning to parse all cs files and detect methods and insert a try catch block with an application. Can you suggest me any parser that I can easily use? or anything that will help me…
every method has its unique number like 5006
public static LogEntry Authenticate(....) { LogEntry logEntry = null; try { .... return logEntry; } catch (CompanyException) { throw; } catch (Exception ex) { logEntry = new LogEntry( '5006', RC.GetString('5006'), EventLogEntryType.Error, LogEntryCategory.Foo); throw new CompanyException(logEntry, ex); } }
I created this for this; http://thinkoutofthenet.com/index.php/2009/01/12/batch-code-method-manipulation/
I had to do something kinda sorta similar (add something to a lot of lines of code); I used regex.
I would create a regex script that found the beginning of each function and insert the try catch block right after the beginning. I would then create another regex script to find the end of the function (by finding the beginning of the function right after it) and insert the try catch block at the end. This won’t get you 100% of the way there, but it will hit maybe 80% which would hopefully be close enough that you could do the edge cases without too much more work.