ExcelDna icon indicating copy to clipboard operation
ExcelDna copied to clipboard

[question] is it possible to see .net exception on windows systems?

Open akasolace opened this issue 2 years ago • 2 comments

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 ....

akasolace avatar Feb 24 '23 15:02 akasolace

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.

govert avatar Feb 27 '23 21:02 govert

Thank you @govert I will test that !

akasolace avatar Mar 03 '23 17:03 akasolace