Is it silly of me to leave unreachable break statements in a case that just throws an Exception anyway? The defensive part of me wants to leave it there in the event that the logic changes. Another part of me doesn't want other developers seeing compiler warnings on 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 a few responses saying that removing the throw at a later date would cause a compiler error. However, simply removing (or commenting) the throw without a break following it would stack the cases, which may be unintended behavior. I'm not saying it's a likely scenario, but...well, is defensive programming about combating only likely scenarios?
break
is no longer needed, I remove them because I build with warnings as errors. – Inapproachable