| 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
|
 |
 |
|
|
subject: Sax Exception conversion to user defined exception not working.
|
|
|