通过向编译器提供一些额外的信息来欺骗一些用户:
final int x;try { x = blah();} catch (MyPanicException e) { abandonEverythingAndDie(); throw new AssertionError("impossible to reach this place"); // or return;}System.out.println("x is " + x);您还可以使
abandonEverythingAndDie()return某个东西(仅从语法上讲,它当然永远不会返回),然后调用
returnabandonEverythingAndDie():
final int x;try { x = blah();} catch (MyPanicException e) { return abandonEverythingAndDie();}System.out.println("x is " + x);和方法:
private static <T> T abandonEverythingAndDie() { System.exit(1); throw new AssertionError("impossible to reach this place");}甚至
throw abandonEverythingAndDie();
与
private static AssertionError abandonEverythingAndDie() { System.exit(1); throw new AssertionError("impossible to reach this place");}


