Something that I've thought sometimes. A tracing mechanism in all branches. And you check in production which lines are never executed. Of course, some things are tricky. For example, handling of cases that should never happen, but maybe those could be annotated.