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

后端 未结 9 1576
你的背包
你的背包 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:15

    I think approaches like this can be very useful (for example, see Erroneously empty code paths). It's even better if you can have that default-throw be compiled away in released code, like an assert. That way you have the extra defensiveness during development and testing, but don't incur the extra code overhead when releasing.

提交回复
热议问题