Thursday, November 22, 2007

Web Services : Just Right Clicking Java Files ??

Lot of Application servers give the provison of directly deploying a java file as webservice very easily ... hiding everything beneath it ... I tried something similar today and noticed something ...

The java functions that are being exposed as web services they must throw Pre Defined Exceptions ... or may be Custom Java Excpetions coz throwing a Exception object is not a good idea as it may throw a Checked or Unchecked exception and user will have to always catch it no matter what the excpetion may be then check the class type using instance of and act accordingly ...

DiSaDvAnTaGeS of Using ~ Throws Exception ~ and ~ Throws Throwable ~

Using throws Throwable and throws Exception subverts the exception checking system. If you do this, callers are forced to catch Throwable or Exception, which may catch both unchecked and checked exceptions. This forces callers to use instanceof to see whether the exception is one that they can deal with.

Essentially, this defers the exception-checking mechanism from compile-time to runtime, which of course converts compile-time errors to runtime errors.

On a related note, there’s not much point in specifying unchecked exception types in a throws clause, for example throws RuntimeException or throws NullPointerException. This serves no purpose except documentation, and it’s better to use a @throws javadoc comment for this, as you can include more information in the javadoc comment.