Chalk me up for wanting exceptions too.

I'm currently building my own REST "framework" on top of Restlet -
essentially a standard way to quickly and easily implement a REST API
using my company's general idioms - and exceptions would be real
handy.

For example, I have a class hierarchy that looks something like this:

  + org.restlet.resource.Resource
     + com.arc90.ext.restlet.resource.Resource (abstract)
        + com.arc90.ext.restlet.resource.CollectionResource (abstract)
           + com.arc90.ext.restlet.resource.JDBCCollectionResource (abstract)
              - com.arc90.someapp.api.rest.resources.SomeResource (concrete)

(BTW I'm relatively new to Java, and formal OOP in general, so if what
I'm doing doesn't make sense, don't skewer me. I welcome constructive
criticism though!)

Some of the abstract Resource subclasses in the middle there provide
implementation, but they're abstract, so I don't know what a real
concrete class is going to need to do, and how it wants to handle
exceptions. So what I'd like to do is just throw exceptions from the
middle layer on up to the higher-level concrete classes, and deal with
them there. I'm talking about, specifically, from methods like
getRepresentation(), put(), post(), delete(), etc. Since they're
declared by the superclass as throwing no exceptions, I can't throw
exceptions in my subclasses.

End result is, if I wanted my high-level class to call the lower-level
method, I have to check statuses before proceeding:

package com.arc90.someapp.api.rest.resources;

import com.arc90.ext.restlet.resource.JDBCCollectionResource;

public class SomeResource extends JDBCCollectionResource {

        @Override
        public void put(Representation representation) {
                // do stuff
                // ...

                // call super.put() to actually do the magic
                super.put(representation);

                // check whether that actually worked or not
                if (getResponse().isSuccess()) {
                        // ok, success, call getRepresentation() to return a 
new representation
                        Representation representation = 
getRepresentation(getPreferredVariant());

                        // oops, now I have to check again whether *that* 
worked or not
                        if (getResponse().isError()) {
                                // deal with the problem...
                        }
                } else {
                        // deal with the problem...
                }
        }

}

Again, I don't know how much my opinion is worth, since I'm still
inexperienced with Java, and, honestly, to robust usage of exceptions,
but this is where my head is at right now.

BTW, I've recently read some interesting essays on exceptions. If
anyone else is interested, I've bookmarked them here:
http://del.icio.us/avi4now/exceptions

Thanks,
Avi

-- 
Avi Flax | Arc90 | http://arc90.com

On 11/28/07, Rob Heittman <[EMAIL PROTECTED]> wrote:
> I haven't rigorously studied the problem yet, but my general feeling is with 
> Tim -- checked exceptions in high level API.

Reply via email to