I may be having a senior moment here (at 22 years old), but I can’t figure out why C# is skipping a statement I have included after a switch. The code goes as follows:
switch (shape)
{
case ToolShape.BasicTool:
EditTool = (LastTool.ToolType == ToolShape.BasicTool)
? new BasicTool((BasicTool)LastTool)
: new BasicTool(ToolNumber, BasicToolType.TypeA,
"Tool " + ToolNumber, "", 1.0, 60.0, 0.0, 0.0, 0.0, 10.0);
break;
case ToolShape.AdvancedTool:
EditTool = (LastTool.ToolType == ToolShape.AdvancedTool)
? new AdvancedTool((AdvancedTool)LastTool)
: new AdvancedTool(AdvancedTool, "Tool " + ToolNumber, "", 1.0, 10.0, 2.0,
AdvancedTool.Light, AdvancedTool.Round);
break;
case ToolShape.SpecialTool:
EditTool = (LastTool.ToolType == ToolShape.SpecialTool)
? new SpecialTool((SpecialTool)LastTool)
: new SpecialTool(SpecialTool, "Tool " + ToolNumber, "",
1.0, 1.0, 90.0);
break;
}
// We never seem to reach anything below here ----------------
LoadToolToForm(EditTool);
It’s never hitting that LoadToolToForm(EditTool) statement. Or a MessageBox.Show("...") I stuck in there, for debugging purposes. Removing the switch works as expected. Putting even a really small switch in there with a single case causes it to exit prematurely again, though.
Is this known behavior? Is there a situation in which breaking from a switch statement causes the function to exit (without ever invoking the return keyword).
If you are sure the code is never passing the switch statement, there is only one other possibility:
There is an exception being thrown in the switch statement, and it is being caught somewhere higher up so the program just continues.
One thing you could try to verify this suggestion would be wrapping your switch in a temporary
try{}catch{}block and showing a MessageBox on Exception, or use lots of breakpoints.