I've recently joined a project where we are extending the functionality of an external application that our company has bought.
It is an Office Add-In with an admin console that allows you to create Windows Forms style forms with code-behind files, and gives you a single place to store common code. This can be quite challenging when implementing code that would be simple in a 'normal' Windows Forms application.
How do I implement global error handling so we can log all errors?
We aren't using Visual Studio and have no access to csproj files so we can't use IL weaving / AOP. We don't have access to the starting point of the application so we can't subscribe to thread or application unhandled exception events. I suspect this is already being subscribed to in the external code, as unhandled exceptions are exposed in a custom error message box by default.
I'm currently looking to see if we can extend the external dlls; however I don't see where I'm going to call our extended code.
The alternative is to go through every method and add a try/catch block in just to log errors, which makes my skin crawl! This project has been running for a year without dealing with error handling yet so it will also take a long time to implement this approach too.
Pseudo-Example class:
namespace Scriptlets
{
using System;
using System.Windows.Forms;
public partial class NewClient : FormScriptType
{
protected override void PageChanged(object sender, PageChangedEventArgs e)
{
ChangeAddressLabels();
}
...
}
}