RegisterUnhandledExceptionHandler and conditional LogDisplay logging

65 views
Skip to first unread message

Terry Aney

unread,
Nov 18, 2015, 1:41:10 AM11/18/15
to Excel-DNA
I have the following code as the handler to RegisterUnhandledExceptionHandler:

// This only is triggered for errors from BTR.Excel.Signatures functions in Excel cells. (not called in VBA calls to VBAHelpers or errors from Ribbon)
private object unhandledExceptionHandler( object exception )
{
    var caller = (ExcelReference)XlCall.Excel(XlCall.xlfCaller); 
    var worksheetName = (string)XlCall.Excel( ExcelDna.Integration.XlCall.xlSheetNm, caller ) + "!"//[Workbook]Sheet
    var address = worksheetName + RBLeHelpers.GetExcelA1Address( caller.RowFirst + 1, caller.ColumnFirst + 1);
    ExcelDna.Logging.LogDisplay.WriteLine( address + " Error: " + exception.ToString() );
 
    // Would like to configure whether or not I 
    lock ( alertCalculationErrorLock )
    {
        if ( !alertCalculationErrorQueued )
        {
            alertCalculationErrorQueued = true;
            ExcelAsyncUtil.QueueAsMacro( () =>
            {
                XlCall.Excel( XlCall.xlcAlert, "There was one or more errors during calculation.  Please review the Diagnostic Display." );
                lock ( alertCalculationErrorLock )
                {
                    alertCalculationErrorQueued = false;
                }
            }
            );
        }
    }
    return ExcelError.ExcelErrorValue;
}

I am trying to figure out how to conditionally call the LogDisplay method based on whether logging/tracing of Errors is turned on.  I've read through https://github.com/Excel-DNA/ExcelDna/wiki/Diagnostic-Logging but it isn't clicking with me on how to configure and check the configuration to determine if I should call the WriteLine and alert box.  Any help would be appreciated.  Let me know if I can provide you any more information.
Reply all
Reply to author
Forward
0 new messages