• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Sax Exception conversion to user defined exception not working.

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
looks as if 'sx.getMessage()' returns null.

 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic