aspose file tools*
The moose likes Beginning Java and the fly likes Exception handling: throw custom exception while using apis Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Exception handling: throw custom exception while using apis" Watch "Exception handling: throw custom exception while using apis" New topic
Author

Exception handling: throw custom exception while using apis

Nick Sher
Ranch Hand

Joined: Nov 10, 2008
Posts: 78
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.


Nick
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Nov 10, 2008
Posts: 78
Thanks Paul, that's what I was doing with the subclass SAXParseException and thought there might be a better practice. Thanks again.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception handling: throw custom exception while using apis