I am getting SAXException while parsing even though my XML is well formed. I am using DOM parser here. It is written in the API that SAXException can be thrown for both error and warning. Is there any way to ignore the warnings coming while parsing and hence no SAXException is thrown.
One more weird behavior I am getting is that when I catch the SAXException, it executes the catch block and after that control goes to the next line from where the exception was thrown, and that line is in try block itself. I'll show this with code example:
Ideally when SAXException is thrown on line 3, control should go to the line 7 and the to line 9 after the catch block. But in current senario control is going to line 4 after line 7. It is something very strange happening. My guess is, is it because of some property of SAXException, when thrown for warning?
Any suggetion/advice in this regard will be helpful. Thanks in advance
That sort of behaviour is against the core control mechanisms of Java. Are you sure this is what is happening, and if so how are you sure?
Also, could you post the stack trace you see? Its is much easier to talk about an Exception when we can see the message you see.
Priya Lavti
Ranch Hand
Joined: Oct 11, 2004
Posts: 41
posted
0
yes I am sure, coz I was actually having System.out.println (SOP) in both the place, catch block and try block. And 1st it is pritning the SOP of catch followed by of the try block.
Here I have caught the SAXException at TransmitManager in a catch block and then throwing my user defined exception and catching that into the jsp file.
And also the 1st line in bold is in the catch block and the last line is in the try block. That is why I am sure controling is flowing from catch block to try block.
And also the 1st line in bold is in the catch block and the last line is in the try block. That is why I am sure controling is flowing from catch block to try block.
Are you sure? Again what you are suggesting would mean that the basic, well understood and extremely well tested control mechanisms in the Java language were broken. If it were me, I would be more inclined to think I had made a mistake, rather than Java is behaving in a way it has never behaved before.
FYI - your exception is almost certainly because you have leading whitespace in your XML file, though I can't be 100% sure. I'm guessing that the code you posted is not the code you are running (I don't see the message "Exception while parsing:" anywhere in the stack trace). Could you post the real code?