title: How to throw an exception in Antlr grammar
body: <p>I have this kind of a grammar,</p>
  
  <pre><code>locationPath returns [CustomParser xpathParser]  
      :^(LOCATION_PATH relativeLocationPath {**Want to throw a exception if this condition matches**})
      |^(LOCATION_PATH absoluteLocationPath {$xpathParser=$absoluteLocationPath.xpathParser;})
      ;
  </code></pre>
  
  <p>What is the way to do it?  I tried with this one</p>
  
  <pre><code>locationPath returns [CustomParser xpathParser]  
      :^(LOCATION_PATH relativeLocationPath {throw new Exception})
      |^(LOCATION_PATH absoluteLocationPath {$xpathParser=$absoluteLocationPath.xpathParser;})
  </code></pre>
  
  <p>But with this one the generated code gives compile Error. Because that method loactionapth doesn't have throws clues at method signature.</p>