Is it “bad” to use try-catch for flow control in .NET?

前端 未结 9 1059
天命终不由人
天命终不由人 2020-11-30 14:51

I just found in a project:

try
{
    myLabel.Text = school.SchoolName;
}
catch
{
    myPanel.Visible = false;
}

I want to talk to the devel

9条回答
  •  攒了一身酷
    2020-11-30 15:55

    You are absolutely right that this is bad. It is bad because it defies intention and because it hurts performance.

    I realize there is room for different programming styles, but personally, I think that even though this works, and I can see what the code is attempting to do, it also hurts readability and code clarity, making it that much more difficult for the maintenance programmers to follow. An if statement is much more appropriate here.

提交回复
热议问题