News for hackers. Stuff that matters.
Re:This should never happen by jdmichal on Thursday March 31, 2016 @11:13AM (#11397747)
Also in Java: Switching or if-else chains on an `enum`. It's still a good practice to include a final `else` or `default` case, but it should really never happen. Actually, inclusion of the `default` case will be enforced by the compiler if it can detect a code path that doesn't return. [0]

    enum Whatever { FOO, BAR }

    if (whatever == FOO) {
    } else if (whatever == BAR) {
    } else {
        // Should never happen!
    }
[0] http://stackoverflow.com/questions/5013194/why-is-default-re...
Re:This should never happen by jrgv on Thursday March 31, 2016 @12:17PM (#11398275)
I'd prefer to throw an exception in that else block:

    throw new AssertionError("Should never happen");
Re:This should never happen by jdmichal on Thursday March 31, 2016 @01:28PM (#11398905)
I just put a comment as an example. I typically log-and-throw.
Re:This should never happen by lancefisher on Thursday March 31, 2016 @12:29PM (#11398403)
This can happen when some other developer adds to your enum not knowing about the use.