Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • When contributing to the KIELER user interface, be sure to respect the Eclipse User Interface Guidelines. By the way, Hallway Usability Testing is a great way to make sure users understand the UI you're designing. Just draw a sketch of your dialog design on a piece of paper, visit a few offices and ask people what they think of your design, how they would use it, and whether they understand it. You're almost certain to discover a few problems with your design that you wouldn't have discovered until after you've written a whole lot of code.
  • The core parts of KIELER can be and are used outside of the Eclipse framework. To that end, be as platform-independent as possible.

We have established certain standards for exception handling.

Expand
titleClick here to read them...

How to Handle Caught Exceptions

Default handling:

Code Block
languagejava
IStatus status = new Status(IStatus.ERROR, MyPlugin.PLUGIN_ID, message, exception);
StatusManager.getManager().handle(status);

If you want to force the status manager to display the error in a dialog, pass the option StatusManager.SHOW.

How to Throw an Exception

The throwable classes are Error, Exception, and RuntimeException. You should choose to throw either an Exception or a RuntimeException. In the first case you must specify the exception in the method's throws declaration (checked exception), in the latter case this is not required (unchecked exception). In most cases it is advisable to throw a more specific subclass in order to give a hint on what has happened.

  • Checked exceptions
    • KielerModelException
      Thrown when a problem occurs with a certain model element.
    • TransformException
      Thrown when a problem occurs during a model transformation.
  • Unchecked exceptions
    • IllegalStateException
      Thrown when the class is in an illegal state, e.g. some class variables have incorrect values or are not compatible with the method parameters.
    • UnsupportedOperationException
      Thrown when a method is not implemented by a concrete subclass or a specific feature given by parameters is not supported.
    • IllegalArgumentException
      Thrown when method parameters have invalid values.
    • WrappedException
      Used to wrap a checked exception into an unchecked one.
    • UnsupportedPartException
      Thrown when no graphical framework bridge is found for an editor part or edit part instance.
    • UnsupportedGraphException
      Thrown when a layout algorithm is executed on a graph that is not supported.

Another hint: often some cleanup code is required that needs to be executed in case of an exception as well as in the normal case. Use a finally block to do this! You can also make a try ... finally block without any catch block, which is very useful.

Checked or Unchecked?

Checked exceptions have the advantage that it is explicitly visible that such an exception can occur and must be handled in some way. They should be used when specific problems are likely to occur and it is known in advance what kind of problems must be covered. A good example is IOException.

Unchecked exceptions have the advantage that it is not required to attach throws declarations for any type of exception that can occur in any part of the call tree. They should be used when it is not known in advance what kind of problems can occur or the problems may occur only in a very deep part of the call tree. This applies to programming errors, which may invoke unchecked exceptions such as NullPointerException or IndexOutOfBoundsException and should always be made visible to the user. Often it is also useful to wrap exceptions into unchecked exceptions:

Code Block
languagejava
try {
    // ...
} catch (IOException e) {
    throw new WrappedException("Oh no, the input file wasn't found!", e);
}

 

  • Feel free to use our utility classes. They are found in KIELER's core projects, particularly kieler.core and kieler.core.ui. If you have written code that you feel could well be part of the KIELER core, tell your supervisor about it.
  • When creating new plug-ins, we have special conventions to be adhered to, summarized on the Naming and Metadata page.