Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception handling: throw custom exception while using apis

 
Nick Sher
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

What I am trying to do is throw a custom exception that I have created from a api method that I am implementing. For example, 'startElement' method throws SAXException, but I want to throw my own exception, how do I do this?

Please help.
 
Paul Clapham
Sheriff
Posts: 21316
32
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't. You throw a SAXException or you don't throw anything.

If I understand you right, and you are writing an implementation of a method which throws SAXException, and the code in that method desperately wants to throw some other exception, then what it should do is throw a SAXException which wraps that other exception. Check the API documentation for SAXException and search for the text "wrap" to see how to create such an exception.
 
Nick Sher
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul, that's what I was doing with the subclass SAXParseException and thought there might be a better practice. Thanks again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic