We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › ParserConfigurationException
Page Index Toggle Pages: 1
ParserConfigurationException (Read 674 times)
ParserConfigurationException
Feb 19th, 2009, 8:40am
 
This isn't specifically a processing feature I'm asking about, but I'm using Java's SAX parser in a sketch and I'm getting a ParserConfigurationException. The code looks like this:

Code:

SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(false);
factory.setNamespaceAware(false);
try {
parser = factory.newSAXParser();
} catch(ParserConfigurationException e) {
println(e.getMessage());
throw e;
} catch(SAXException e) {
println(e.getMessage());
throw e;
}


I get "Unhandled exception type ParserConfigurationException" on the line that calles newSAXParser. It doesn't print a message and there's no stack trace in the PDE or in the console. I can't seem to find any details on why this gets thrown.
Curiously, if I don't explicitly catch SAXException it throws SAXException instead. If I don't use try/catch at all it throws the ParserConfigurationException.

Anyone know what the issue is or how I can get more info on why this is getting thrown?
I'm using MacOSX 10.4, Java 1.5.0_16
Re: ParserConfigurationException
Reply #1 - Feb 19th, 2009, 10:04am
 
I had to add some code to reproduce that:
Code:
import javax.xml.parsers.*;
import org.xml.sax.*;

SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(false);
factory.setNamespaceAware(false);
SAXParser parser;
try {
parser = factory.newSAXParser();
} catch(ParserConfigurationException e) {
println(e.getMessage());
throw e;
} catch(SAXException e) {
println(e.getMessage());
throw e;
}


You are confusing a compilation message (Unhandled exception) with a runtime exception.
When I run the above code, PDE highlights the line with throw e, to show where the compilation error occurs.

The problem is that you correctly catch the exception, but re-throw it, so it needs to be caught at a higher level!
Just get rid of the throw lines (they are not necessary in a simple sketch) and you are good to go.

Note: I want for quite some time to explain how to use Java's newly built in XML parsers (SAX, like you, StAX, or even DOM). It would offer a nice alternative to Processing's one or proXML: built in, no external library, robuster, correct handling of encoding and more complex XML. But slightly harder to use...
I should write a hack about that.
Page Index Toggle Pages: 1