You can either bubble all your exceptions up to the root of your console application and wrap in a big try/catch that handles all exceptions, or at the start of your console application you can add an event handler to your app domain for "Unhandled Exception" event and all exceptions that go unhandled will get routed there.
using System;
using System.Security.Permissions;
public class Example
{
[SecurityPermission(SecurityAction.Demand, Flags=SecurityPermissionFlag.ControlAppDomain)]
public static void Main()
{
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += new UnhandledExceptionEventHandler(MyHandler);
try {
throw new Exception("1");
} catch (Exception e) {
Console.WriteLine("Catch clause caught : {0} \n", e.Message);
}
throw new Exception("2");
}
static void MyHandler(object sender, UnhandledExceptionEventArgs args)
{
Exception e = (Exception) args.ExceptionObject;
Console.WriteLine("MyHandler caught : " + e.Message);
Console.WriteLine("Runtime terminating: {0}", args.IsTerminating);
}
}
source
Update
Not a lot of great simple options for doing what you're trying to do. One thing you could try out is installing msysgit / cygwin and use unix tools to find replace all occurrences. This would be pretty experimental and you'd have to do some heavy testing.
find <project dir> -type f -exec sed -i '.bak' 's/catch\(Exception ex\)\r\n{/catch\(Exception ex\)\r\n{\r\nModernExceptionHandler.handle(ex);\r\n/g' {} +
Which should recursively walk your project directories and replace occurrences of -
catch(Exception ex)
{
with
catch(Exception ex)
{
ModernExceptionHandler.handle(ex);
Files that get modified will have a backup version saved alongside them with .bak file extension.
More info on find / sed