A little too aggressive catching exceptions

Add-in Express™ Support Service
That's what is more important than anything else

A little too aggressive catching exceptions
 
Stuart Kolodner




Posts: 35
Joined: 2009-10-09
I found a case where Add-In-Express is catching an exception raised in the interop layer before my application can catch it. I have some code like:
  
        try
        {
            ... stuff removed here.
            return sheet.get_Range(cellRef, cellRef) as Range;
        }
        catch
        {
            // Couldn't parse the reference.
            return null;
        }


The first time the exception fires, the add-in-express exception handler catches it and shows its dialog before my code can catch the exception. On all subsequent times, the exception is simply caught by my code as I expect.

This worked correctly in the previous version of Add-In-Express. This is a case where I want to let the exception be raised and caught since I'm depending on Excel to tell if it's a good reference.
Posted 06 May, 2013 11:01:11 Top
Stuart Kolodner




Posts: 35
Joined: 2009-10-09
Here's the exception details with personal information removed. Further testing seems to show that add-in-express only caches this exception if its raised prior to doing other stuff. By "other stuff" I mean if it happens before other calls through the interop layer, although I cannot definitively say on the first call or if the call happens before such and such call.

The stack details:


Detailed technical information follows:
---
(Inner Exception)
Date and Time: 5/6/2013 12:23:35 PM

Application Domain: xxxxxxxxxxxxxxxxxxxxxxx
Assembly Codebase: file:///C:/windows/assembly/GAC_MSIL/Microsoft.Office.Interop.Excel/14.0.0.0__71e9bce111e9429c/Microsoft.Office.Interop.Excel.dll
Assembly Full Name: Microsoft.Office.Interop.Excel, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c
Assembly Version: 14.0.0.0

Exception Source: Microsoft.Office.Interop.Excel
Exception Type: System.AccessViolationException
Exception Message: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Exception Target Site: get_Range

---- Stack Trace ----
Microsoft.Office.Interop.Excel._Worksheet.get_Range(Cell1 As Object, Cell2 As Object)
Microsoft.Office.Interop.Excel.dll: N 00000 (0x0) JIT
xxxxxxxxx.ExcelHandler.ResolveReference(cell As Range)
ExcelHandler.cs: line 0683, col 25, IL 0230 (0xE6)

... dialog open here ... lots of stuff removed here from stack trace.

AddinExpress.MSO.ADXRibbonButton.DoInternalAction(e As ADXRibbonOnActionEventArgs)
Microsoft.Office.Interop.Excel.dll: N 0035 (0x23) IL



(Outer Exception)
Date and Time: 5/6/2013 12:23:35 PM

Assembly Codebase: file:///C:/windows/assembly/GAC_MSIL/AddinExpress.MSO.2005/7.2.4055.2005__4416dd98f0861965/AddinExpress.MSO.2005.dll
Assembly Full Name: AddinExpress.MSO.2005, Version=7.2.4055.2005, Culture=neutral, PublicKeyToken=4416dd98f0861965
Assembly Version: 7.2.4055.2005

Exception Source:
Exception Type: AddinExpress.MSO.ADXExternalException
Exception Message: An error has occurred in the code of the add-in.
Exception Target Site: Object reference not set to an instance of an object.

---- Stack Trace ----

Posted 06 May, 2013 11:38:04 Top
Andrei Smolin


Add-in Express team


Posts: 14129
Joined: 2006-05-11
Hello Stuart,

Exception Type: AddinExpress.MSO.ADXExternalException
Exception Message: An error has occurred in the code of the add-in.


This means Add-in Express has caught an ADXExternalException exception. By default, handling such an exception shows an error message. You can handle this another way in an event handler for the OnError event of the add-in module.

Stuart Kolodner writes:
I found a case where Add-In-Express is catching an exception raised in the interop layer before my application can catch it.


Basing on the fact that Add-in Express intercepts the exception and also on what is written at http://msdn.microsoft.com/en-us/library/ms404228.aspx, I suppose that your code just doesn't intercept the exception properly. Can you please check if replacing catch with catch (System.Exception e) in your code helps?

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 07 May, 2013 05:47:28 Top
Stuart Kolodner




Posts: 35
Joined: 2009-10-09
For some reason, the exception isn't caught the first time through that code Doesn't matter what the catch looks like; empty or "System.Exception". On subsequent times raising the exception, it works fine.

I switched fr om building a release version to a debug version and now after the exception is raised, I see cases where Excel crashes on subsequent clicks on the sheet. The exception isn't caught anywhere and I can't tell what code is crashing.

The problem doesn't occur when running under the debugger. In that case, the exception is always caught by my code.

Looks like a bug somewh ere ... as I moved my add-in from .Net Framework 3.5 to 4.0 and Visual Studio 2008 to 2012.

Will play some more ...
Posted 07 May, 2013 09:41:11 Top
Andrei Smolin


Add-in Express team


Posts: 14129
Joined: 2006-05-11
Hello Stuart,

Can you please send me some code for testing?

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 08 May, 2013 01:22:33 Top
Andrei Smolin


Add-in Express team


Posts: 14129
Joined: 2006-05-11
Please specify Excel version, bitness and serive pack.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 08 May, 2013 01:31:22 Top