Throwing exceptions in switch statements when no specified case can be handled

后端 未结 9 1577
你的背包
你的背包 2021-01-30 15:52

Let\'s say we have a function that changes a password for a user in a system in an MVC app.:

public JsonResult ChangePassword
    (string username, string curren         


        
9条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-30 16:40

    I've used this practice before for specific instances when the enumeration lives "far" from it's use, but in cases where the enumeration is really close and dedicated to specific feature it seems like a little bit much.

    In all likelihood, I suspect an debug assertion failure is probably more appropriate.

    http://msdn.microsoft.com/en-us/library/6z60kt1f.aspx

    Note the second code sample...

提交回复
热议问题