Code example for SAXException

Methods: getMessage

0
  public void test_testValid() throws Exception { 
    try { 
      AstRoot res = parse("<root/>");
      Assert.fail("no exception");
    } catch (SAXException ex) {
      Assert.assertEquals("attribute name is absent", ex.getMessage());
    } 
  } 
 
  private AstRoot parse(String text) throws SAXException {
    try { 
      SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
      TestParserHandler handler = new TestParserHandler();
      saxParser.parse(new InputSource(new CharArrayReader(text.toCharArray())), handler);
      return (AstRoot) handler.getResult();
    } catch (IOException ex) {
      Assert.fail(ex.getMessage() + ": exception");
      return null; 
    } catch (ParserConfigurationException ex) {
      Assert.fail(ex.getMessage() + ": exception");