Is it really stupid for me to leave unreachable break statements in a case that just throws an exception? The protective part of me wants to leave it there, in case of a change in logic. The other part of me does not want other developers to see compiler warnings in my code ("unreachable code detected").
switch (someInt) { case 1: // Do something break; case 2: // Do something else break; case 3: // Oh, we don't use threes here! throw new Exception("Business rules say don't use 3 anymore"); break; // Unreachable...until the fickle business rules change... default: throw new Exception("Some default exception"); break; // Unreachable...until...well, you get the idea. }
What to do?
UPDATE
I see several answers saying that removing the throw later will result in a compiler error. However, simply deleting (or commenting) the cast without interruption after it would add up cases that may be unintended behavior. I'm not saying that this is a likely scenario, but ... well, is this defensive programming to deal with likely scenarios?
source share