/**
  * Implementation of the ParseExceptionListener interface.
  *
  * @param ex Exception that is given to us by the parser.
  * @throws ParseException If we choose to reject the header or message.
  */
 public void handleException(
     ParseException ex, SIPMessage sipMessage, Class hdrClass, String header, String message)
     throws ParseException {
   if (sipStack.isLoggingEnabled()) this.sipStack.logWriter.logException(ex);
   // Log the bad message for later reference.
   if ((hdrClass != null)
       && (hdrClass.equals(From.class)
           || hdrClass.equals(To.class)
           || hdrClass.equals(CSeq.class)
           || hdrClass.equals(Via.class)
           || hdrClass.equals(CallID.class)
           || hdrClass.equals(RequestLine.class)
           || hdrClass.equals(StatusLine.class))) {
     sipStack.logWriter.logError("BAD MESSAGE!");
     sipStack.logWriter.logError(message);
     throw ex;
   } else {
     sipMessage.addUnparsed(header);
   }
 }
  /**
   * Logs exceptions that have occurred in the application while processing events originating from
   * the stack.
   *
   * @param eventClass the class of the jain-sip event that we were handling when the exception was
   *     thrown.
   * @param exc the exception that we need to log.
   */
  private void logApplicationException(Class<DialogTerminatedEvent> eventClass, Throwable exc) {
    String message = "An error occurred while processing event of type: " + eventClass.getName();

    logger.error(message, exc);
    if (logger.isDebugEnabled()) logger.debug(message, exc);
  }