Skip to content

Commit 2770646

Browse files
authored
Merge pull request #3433 from mansellan/3430
Added try/catch and logging when a command's 'CanExecute' implementation throws an exception, to prevent derailing the entire menu creation when one single command bombs.
2 parents 4d9716b + f2112dc commit 2770646

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

RetailCoder.VBE/UI/Command/MenuItems/FormDesignerRefactorRenameCommandMenuItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public FormDesignerRefactorRenameCommandMenuItem(CommandBase command)
1515

1616
public override bool EvaluateCanExecute(RubberduckParserState state)
1717
{
18-
return state.Status == ParserState.Ready && Command.CanExecute(null);
18+
return state != null && state.Status == ParserState.Ready && Command.CanExecute(null);
1919
}
2020
}
2121
}

RetailCoder.VBE/UI/Command/MenuItems/ParentMenus/ParentMenuItemBase.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,16 @@ public void EvaluateCanExecute(RubberduckParserState state)
124124
var commandItem = kvp.Key as ICommandMenuItem;
125125
if (commandItem != null && kvp.Value != null)
126126
{
127-
kvp.Value.IsEnabled = commandItem.EvaluateCanExecute(state);
127+
try
128+
{
129+
kvp.Value.IsEnabled = commandItem.EvaluateCanExecute(state);
130+
}
131+
catch (Exception exception)
132+
{
133+
kvp.Value.IsEnabled = false;
134+
Logger.Error(exception, "Could not evaluate availability of commmand menu item {0}.", kvp.Value.Tag ?? "{Unknown}");
135+
}
136+
128137
}
129138
}
130139
}

0 commit comments

Comments
 (0)