Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#7 Improve Exception Classes

open
nobody
None
5
2009-01-16
2009-01-16
Joe L
No

I'd like to use Simple XML to help parse requests to one of my API's I'm adding to a webapp. I'd like better programmatic access to specific attributes, elements, etc. that actually cause a validation error. While the current exceptions are helpful for me, they aren't useful to display to a caller of my API. They aren't in a format that would be helpful to display to a caller of my API. I'm probably going to have to resort to some sort of String extraction to properly display them as an error message.

What I'd like is extended properties added to each type of Exception that Simple XML can throw. For example, this is an a typical error thrown by your API:

Exception in thread "main" org.simpleframework.xml.core.ValueRequiredException: Unable to satisfy @org.simpleframework.xml.Attribute(name=, empty=, required=true) on field 'name' for class net.cloudhopper.simplexml.demo.Person at line 1

What I'd actually prefer is that you add properties to the ValueRequiredException class that let me programmatically access the errors. For example, you'd add "getLine()" and "getAttributeName" or maybe just "getName()", etc. That would help me build me own error message I'd display to a caller of my API. If I'm parsing only a snippet of XML within a larger document, I could access getLineNumber() and add it to the line number I know I'm on.

You could add similar properties to every exception you currently throw. This would be immensely helpful to me and probably other users!

Finally, I'm wondering why you generically throw an "Exception" in your Serializer object? Why don't you at least throw PersistenceException? Maybe that could be changed in a future version? I doubt it would break any backwards compatibility if most folks are already generically catching Exception.

Discussion

  • ARKBAN
    ARKBAN
    2009-01-19

    I agree with the submitter's last comment that Serializer should not throw "Exception", its far too generic. It makes distinguishing a Serializer exception from other exceptions awkward at best.

    I agree with his other comments, but I haven't encountered them yet. (I'm just beginning to use Simple.)

     
  • Hi,

    Thats a fair comment. You would have got an immediate response on the mailing list, as this is where I usually look.

    Niall