...
Code Block |
---|
@lexer::members { @Override public void reportError(RecognitionException e) { Thrower.sneakyThrow(e); } /** * See "Puzzle 43: Exceptionally Unsafe" from Bloch Gafter, <i>Java Puzzlers</i>. Addison Wesley 2005. */ static class Thrower { private static Throwable t; private Thrower() throws Throwable { throw t; } public static synchronized void sneakyThrow(Throwable t) { Thrower.t = t; try { Thrower.class.newInstance(); } catch (InstantiationException e) { throw new IllegalArgumentException(e); } catch (IllegalAccessException e) { throw new IllegalArgumentException(e); } finally { Thrower.t = null; // Avoid memory leak } } } } |
Or, more succinctly
Code Block |
---|
@lexer::members {
@Override
public void reportError(RecognitionException e) {
throw new IllegalArgumentException(e);
}
}
|