How to create specific error messages based on parse exceptions in JavaCC
<p>I'm making a JavaCC program to accept a certain language. I've done this but cannot understand how to use a generated ParseException to determine the issue in the input, and customise the output error message.</p>

<p>So far my code looks like:</p>

<pre><code>try {
  task parser = new task(System.in);
  parser.start();
  System.out.println("YES"); // If accepted print YES.
} catch (ParseException e) {
  System.out.println("NO"); // If rejected print NO.
  switch (e) {
    case 1:
       System.err.println("Some error case")
    case 2:
       ...
  }  
}
</code></pre>

<p>Some sources I've looked at are the documentation for ParseException and the JavaCC error handling pages. Neither have helped me understand much better.</p>

<p>If anyone could help/hint I would be really thankful.</p>