Trapping Excel unhandled exceptions with ExcelDna

652 views
Skip to first unread message

Jm Pironneau

unread,
Jul 17, 2013, 9:19:18 AM7/17/13
to exce...@googlegroups.com
Hello all,
 
We are trying to make sure that Excel never crashes when our Add-In produces exceptions.
So we went down the road of the AppDomain stuffs like AppDomain.CurrentDomain.UnhandledException and it does not work.
 
This result is understandable because the Application is Excel and our XLL is just a module loaded that runs under Excel.
 
If someones knows a way to be sure Excel cannot be crashed by our Add-In we would love to learn how to do it.
 
Regards
Jean-Marie

Govert van Drimmelen

unread,
Jul 17, 2013, 9:56:24 AM7/17/13
to exce...@googlegroups.com
Hi Jean-Marie,

It is useful to identify particular cases where your add-in is able to crash Excel.

Excel-DNA ensures that all UDFs and C API macro calls are wrapped in proper exception handlers (unless you explicitly opt out with IsExceptionSafe=true).
Incorrect calls to the C API through Excel-DNA should not crash Excel.
Exceptions in ribbon handlers should not crash Excel.

I can think of only the following cases that will crash Excel:
* A UDF that is mistakenly marked IsExceptionSafe=true, and throws and unhandled exception
* Use of the C API from within a ribbon handler or RTD callback (I've tried to prevent at least the RTD cases in recent check-ins).
* Use of the COM Automation interfaces from within a UDF calculation, though I don't have a repeatable example of this crashing.
* Causing a stack overflow anywhere in your add-in.

The StackOverflowException is particularly problematic, as it is can never be caught as a normal exception. When hosting the .NET runtime, a process has the option to set a flag whereby a stack overflow causes the AppDomain to unload, instead of the process to terminate. However, Excel interferes with our hosting of the runtime so that we can't get that option set, and if the runtime is initially loaded by some other mechanism, the option cannot be modified later.

If you know of other ways in which your add-in can crash Excel, please post some details.
That way we can at least keep track of the potentially dangerous behaviour.

Regards,
Govert

Jm Pironneau

unread,
Jul 19, 2013, 3:00:57 AM7/19/13
to exce...@googlegroups.com
Hello Govert,
 
Thanks for your answer, quick and detailed as always.
I will definitively try to find ways to have Excel crashed (like trying to access a range of an unexisting worksheet ?) and will keep u posted if I find any.

JM
Reply all
Reply to author
Forward
0 new messages