ExcelDna
ExcelDna copied to clipboard
[question] is it possible to see .net exception on windows systems?
Is there a way to see on Windows exception thrown by .net when calling the Addin? I tried on Event Viewer, but I could not find anything ....
In your add-in you can set up an exception handler that is called for any UDF function exceptions.
using System.Diagnostics;
using ExcelDna.Integration;
public class AddIn : IExcelAddIn
{
public void AutoOpen()
{
// Only called from UDF exceptions, not Ribbon etc.
ExcelIntegration.RegisterUnhandledExceptionHandler(HandleError);
}
public void AutoClose() { }
private object HandleError(object ex)
{
Debug.Print(ex.ToString());
// Log exceptions or write to Windows event log here
}
}
There are some other mechanisms to catch exceptions from other sources - e.g. the AppDomain.UnhandledException event.
Thank you @govert I will test that !