title: Antlr4 how to detect unrecognized token and given sentence is invalid
body: <p>I am trying to develop a new language with Antlr. Here is my grammar file :</p>
  
  <pre><code>grammar test;
  
  program : vr'.' to'.' e 
          ;
  e: be
   | be'.' top'.' be
   ;
  be: 'fg' 
    | 'fs' 
    | 'mc' 
    ;
  to: 'n' 
    | 'a' 
    | 'ev' 
    ;
  vr: 'er' 
    | 'fp' 
    ;
  top: 'b' 
    | 'af' 
    ;
  Whitespace : [ \t\r\n]+ -&gt;skip 
             ;
  </code></pre>
  
  <p><strong>Main.java</strong></p>
  
  <pre><code>String expression = "fp.n.fss";
  //String expression = "fp.n.fs.fs";
  ANTLRInputStream input = new ANTLRInputStream(expression);
  testLexer lexer = new testLexer(input);
  CommonTokenStream tokens = new CommonTokenStream(lexer);
  testParser parser = new testParser(tokens);
  //remove listener and add listener does not work
  ParseTree parseTree = parser.program();
  </code></pre>
  
  <p>Everything is good for valid sentences. But I want to catch unrecognized tokens and invalid sentences in order to return meaningful messages. Here are two test cases for my problem.</p>
  
  <blockquote>
    <p><strong>fp.n.fss</strong>   => anltr gives this error token recognition error at: 's' but i could not handle this error. There are same example error handler class which use BaseErrorListener but in my case it does not work.<br>
    <strong>fp.n.fs.fs</strong> => this sentence is invalid for my grammar but i could not catch. How can i catch invalidations like this sentence?</p>
  </blockquote>