You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Paul Flanagan <fl...@onetel.net.uk> on 2001/04/09 18:40:33 UTC

Problem with Error Handling

Can any one tell me if declaring an error handler such as:     

parser.setErrorHandler( new xmlErrorHandler() ) ;

    try
    {
      parser.parse( fn ) ;
    }
    catch( Exception e )
    {
      consoleOutput( e + ":  Exception invoking parser", 0 ) ;
    }


is all I have to do in order to see errors in an XML document when using the DOM parser?   What else do I need to do in order to see the line number etc that the error is on?  Class xmlErrorHandler is shown below.

Thanks in advance 

Paul



import org.xml.sax.ErrorHandler ;
import org.xml.sax.SAXParseException ;

public class xmlErrorHandler implements ErrorHandler
{
  public void error( SAXParseException saxe )
  {
    showDetails( "ERROR: " , saxe ) ;
  }

  public void fatalError( SAXParseException saxe )
  {
    showDetails( "FATAL ERROR: " , saxe ) ;
  }

  public void warning( SAXParseException saxe )
  {
    showDetails( "WARNING: " , saxe ) ;
  }

  void showDetails( String s, SAXParseException e )
  {
    String output ;

    output = s + "[" + e.getLineNumber() + ":" + e.getColumnNumber() +"] "+ e.getPublicId() ;

    System.out.println( output ) ;
    System.out.println( "--> " + e.getMessage() ) ;
  }
}