Skip to content

Commit 8d09b18

Browse files
committed
Catch and log initialization exception.
1 parent 4fa789d commit 8d09b18

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

RetailCoder.VBE/UI/Command/MenuItems/CommandBars/AppCommandBarBase.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,15 @@ public virtual void Initialize()
6969
Item.IsVisible = true;
7070
foreach (var item in _items.Keys.OrderBy(item => item.DisplayOrder))
7171
{
72-
_items[item] = InitializeChildControl(item);
72+
try
73+
{
74+
_items[item] = InitializeChildControl(item);
75+
76+
}
77+
catch (Exception e)
78+
{
79+
Logger.Error(e, $"Initialization of the menu item for {item.Command.GetType().Name} threw an exception.");
80+
}
7381
}
7482
}
7583

@@ -159,21 +167,14 @@ private void RemoveChildren()
159167
_items.Clear();
160168
}
161169

162-
// note: HAAAAACK!!!
163-
private static int _lastHashCode;
164-
165170
private void child_Click(object sender, CommandBarButtonClickEventArgs e)
166171
{
167172
var item = _items.Select(kvp => kvp.Key).SingleOrDefault(menu => menu.GetType().FullName == e.Control.Tag);
168-
if (item == null || e.Control.Target.GetHashCode() == _lastHashCode)
173+
if (item == null)
169174
{
170175
return;
171176
}
172177

173-
// without this hack, handler runs once for each menu item that's hooked up to the command.
174-
// hash code is different on every frakkin' click. go figure. I've had it, this is the fix.
175-
_lastHashCode = e.Control.Target.GetHashCode();
176-
177178
Logger.Debug("({0}) Executing click handler for commandbar item '{1}', hash code {2}", GetHashCode(), e.Control.Caption, e.Control.Target.GetHashCode());
178179
item.Command.Execute(null);
179180
}

0 commit comments

Comments
 (0)