It's not a secret anymore!
The moose likes Java in General and the fly likes Sax Exception conversion to user defined exception not working. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Sax Exception conversion to user defined exception not working." Watch "Sax Exception conversion to user defined exception not working." New topic
Author

Sax Exception conversion to user defined exception not working.

Mohammed Ajmal
Greenhorn

Joined: Sep 20, 2004
Posts: 29
Hi,

I have written a parser in java using SAXParser.
Also, schema validation is done. So when I give a incorrect xml it throws SAXException and I am able to catch the same. But on catching it I am conveting it to userDefined exception and throwing the same to client(java application), but on catching the same in client it is getting converted to null pointer exception and i have to put a catch( Exception ex) block to catch it, it is not getting catched in userdefined catch block.

code snippet
----------------------------
parser:

method parseInput (...) throws parseException

catch(SAXException sx)
{
throw new parseException( sx.getMessage());
}

client:

try
{
parseInput()
}
catch( parseException pe )
{
...
}
catch ( Exception e)
{
// Here it is getting caught.
System.out.println(" prints exception message as " + e.getMessage())) as NULL.
}
}

-- End -----------------------------------

Could some one throw pointers on the same.

Your help is highly appreciated and thanks for the same.
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

looks as if 'sx.getMessage()' returns null.



http://home.arcor.de/hirnstrom/bewerbung
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Rather than just taking the message from the "causing exception". You should use the "exception chaining paradigm" by writing an constructor in your custom exception class that takes an Exception parameter as well as the String message. In JDK 1.4 and beyond, this is already supported in the base Exception class, so it is farily easy to implement. If you use this paradigm, you would then be able to do something like this:


HTH

Layne
[ March 19, 2005: Message edited by: Layne Lund ]

Java API Documentation
The Java Tutorial
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Sax Exception conversion to user defined exception not working.
 
Similar Threads
Using Hibernate to Read XML
'reading' an xml document - what am i doing wrong?
javax xml parsers FactoryConfigurationError
Question on "Handle Or Declare" rule for Exceptions - K&B book Page 374 (Exam Watch)
try and catch