class ResultHandler implements AutoCloseable {
  
  protected static final int CONTEXT_SIZE = 50;
  protected static final String MARKER_START = "<err>";
  protected static final String MARKER_END = "</err>";

  protected int sentenceCount = 0;
  protected int errorCount = 0;

  protected abstract void handleResult(Sentence sentence, List<RuleMatch> ruleMatches, Language language);

  private final int maxSentences;
  private final int maxErrors;

  protected ResultHandler(int maxSentences, int maxErrors) {
    this.maxSentences = maxSentences;
    this.maxErrors = maxErrors;
  }

  protected void checkMaxSentences(int i) {
    if (maxSentences > 0 && sentenceCount >= maxSentences) {
      throw new DocumentLimitReachedException(maxSentences);
    }
  }

  protected void checkMaxErrors(int i) {<FILL_FUNCTION_BODY>}

}

    if (maxErrors > 0 && errorCount >= maxErrors) {
      throw new ErrorLimitReachedException(maxErrors);
    }
  
<no_super_class>