Skip to content

Commit 9670ce9

Browse files
committed
Fix empty line error in WorkbookProvider
Add exception handlers to the COM event listeners
1 parent 7ce33ce commit 9670ce9

File tree

2 files changed

+52
-19
lines changed

2 files changed

+52
-19
lines changed

Source/ExcelDna.IntelliSense/Providers/WorkbookIntelliSenseProvider.cs

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ public IEnumerable<FunctionInfo> GetFunctionInfos()
8484
string description = regInfo[i, 2] as string;
8585
string helpTopic = regInfo[i, 3] as string;
8686

87+
if (string.IsNullOrEmpty(functionName))
88+
continue;
89+
8790
List<FunctionInfo.ArgumentInfo> argumentInfos = new List<FunctionInfo.ArgumentInfo>();
8891
for (int j = 4; j <= numCols - 1; j += 2)
8992
{
@@ -216,44 +219,75 @@ public IList<FunctionInfo> GetFunctionInfos()
216219
void Excel_WorkbookOpen(Workbook wb)
217220
{
218221
var name = wb.Name;
219-
var regInfo = new WorkbookRegistrationInfo(name);
220-
lock (_workbookRegistrationInfos)
222+
try
223+
{
224+
var regInfo = new WorkbookRegistrationInfo(name);
225+
lock (_workbookRegistrationInfos)
226+
{
227+
_workbookRegistrationInfos[name] = regInfo;
228+
RegisterWithXmlProvider(wb);
229+
OnInvalidate();
230+
}
231+
}
232+
catch (Exception ex)
221233
{
222-
_workbookRegistrationInfos[name] = regInfo;
223-
RegisterWithXmlProvider(wb);
224-
OnInvalidate();
234+
Logger.Provider.Error(ex, $"Unhandled exception in {nameof(Excel_WorkbookOpen)}, Workbook: {name}");
225235
}
226236
}
227237

228238
void Excel_WorkbookBeforeClose(Workbook wb, ref bool cancel)
229239
{
230-
// Do we have to worry about renaming / Save As?
231-
// Do we have to worry about other BeforeClose handlers cancelling the close?
232-
lock (_workbookRegistrationInfos)
240+
var name = wb.Name;
241+
try
242+
{
243+
// Do we have to worry about renaming / Save As?
244+
// Do we have to worry about other BeforeClose handlers cancelling the close?
245+
lock (_workbookRegistrationInfos)
246+
{
247+
_workbookRegistrationInfos.Remove(name);
248+
UnregisterWithXmlProvider(wb);
249+
}
250+
}
251+
catch (Exception ex)
233252
{
234-
_workbookRegistrationInfos.Remove(wb.Name);
235-
UnregisterWithXmlProvider(wb);
253+
Logger.Provider.Error(ex, $"Unhandled exception in {nameof(Excel_WorkbookBeforeClose)}, Workbook: {name}");
236254
}
255+
237256
}
238257

239258
void Excel_WorkbookAddinInstall(Workbook wb)
240259
{
241260
var name = wb.Name;
242-
var regInfo = new WorkbookRegistrationInfo(name);
243-
lock (_workbookRegistrationInfos)
261+
try
262+
{
263+
var regInfo = new WorkbookRegistrationInfo(name);
264+
lock (_workbookRegistrationInfos)
265+
{
266+
_workbookRegistrationInfos[name] = regInfo;
267+
RegisterWithXmlProvider(wb);
268+
OnInvalidate();
269+
}
270+
}
271+
catch (Exception ex)
244272
{
245-
_workbookRegistrationInfos[name] = regInfo;
246-
RegisterWithXmlProvider(wb);
247-
OnInvalidate();
273+
Logger.Provider.Error(ex, $"Unhandled exception in {nameof(Excel_WorkbookAddinInstall)}, Workbook: {name}");
248274
}
249275
}
250276

251277
void Excel_WorkbookAddinUninstall(Workbook wb)
252278
{
253-
lock (_workbookRegistrationInfos)
279+
var name = wb.Name;
280+
try
281+
{
282+
lock (_workbookRegistrationInfos)
283+
{
284+
_workbookRegistrationInfos.Remove(wb.Name);
285+
UnregisterWithXmlProvider(wb);
286+
}
287+
}
288+
catch (Exception ex)
254289
{
255-
_workbookRegistrationInfos.Remove(wb.Name);
256-
UnregisterWithXmlProvider(wb);
290+
Logger.Provider.Error(ex, $"Unhandled exception in {nameof(Excel_WorkbookAddinUninstall)}, Workbook: {name}");
257291
}
258292
}
259293

Source/ExcelDna.IntelliSense/UIMonitor/FormulaEditWatcher.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Diagnostics;
32
using System.Threading;
43
using System.Windows;
54
using System.Windows.Automation;

0 commit comments

Comments
 (0)