Services ExceptionHomepage  « Case Study « Services Exception

Whether accessing the Manufacturer file locally or remotely problems can arise using I/O and we can also have problems with remote access. So we need to catch and pass back exception information to the GUI users about services exceptions that are not covered elsewhere within the code. In this lesson we will create a ServicesException class to handle exceptions thrown when using our services.

Compiling The ServicesException Classgo to top of page Top

The following ServicesException class will be be thrown when an exception occurs when using our services.

Cut and paste the following code into your text editor and save it in the   c:\_Case_Study\src\services directory.


package services;

/**
 * Holds all services exceptions that may occur in Services
 * 
 * @author Kevin 
 * @version 1.0
 * @see Services
 *
 */
public class ServicesException extends RuntimeException {

    /**
     * A version number for the ServicesException class so that serialisation 
     * can occur without worrying about the underlying class changing 
     * between serialisation and deserialisation.
     * 
     */
    private static final long serialVersionUID = 871964L;

    /**
     * Create a default ServicesException instance.
     * 
     */
    public ServicesException() {
        super();
    }

    /**
     * Create a ServicesException that returns a String.
     * 
     */
    public ServicesException(String e) {
        super(e);
    }

    /**
     * Create a ServicesException instance and chains an exception.
     * 
     * @param e The exception to wrap
     */
    public ServicesException(Throwable e) {
        super(e);
    }
}

Compiling Our Source File With the -d Option

Open your command line editor:

Change to directory  cd c:\_Case_Study\src\services

Compile ServicesException.java using the java compiler with the -d option
  javac -d ..\..\classes ServicesException.java

Because we have used a package (package services;) at the top of the code the compiler has created this directory within the classes directory. When we look in the services directory we can see the compiled ServicesException.class file.

compile ServicesException

Related Java6 Tutorials

Flow Control - Handling Exceptions
Flow Control - Declaring Exceptions
Flow Control - Creating Our Own Exceptions
Swing - RMI - Serialization


What's Next?

In our final lesson of the section we create the Services and RemoteServices interfaces required for the case study.

<<  Controller Part 1                   Services Interfaces  >>

go to home page Homepage go to home page Top

All the Controller Part 1 lessons are listed below. Click a link to go to that lesson.


Controller Part 1

Services Exception

ServicesException Class

Services Interfaces