LeftMenu/mywms64.gif

Main page

FAQ
HOWTO
Components

Page Index

myWMS News
Mailinglist
lexicon

Recent Changes
WikiEtiquette

Find pages
Unused pages
Undefined pages

Impressum

Set your name in
UserPreferences

Edit this page


Referenced by
...nobody




JSPWiki v2.2.33
i18n support


[RSS]

Exception Handling


Exception Handling in Generall

  1. Whenever you can handle an exception, catch it and handle it.
  2. Whenever you cannot handle an exception, don't catch it, but forward it to the caller of the method.
  3. Be responsible for your own ressources.

Forwarding Exceptions

Often it comes to the point, where the exception you cannot handle must be forwarded to the caller of the method, but because the interface of the method does not announce the special exception it cannot be done directly. In this case:

Try to wrap the exception into an announced exception:

public void myExample(int i) throws IllegalArgumentException {
  try {
    [...]
  }
  catch(ProprietaryException ex) {
    throw new IllegalArgumentException(ex);
  }
}

Wrap the catched exception into a RuntimeException:

public void myExample() {
  try {
    [...]
  }
  catch(ProprietaryException ex) {
    throw new RuntimeException(ex);
  }
}

RuntimeExceptions

RuntimeExceptions should not be catched at all. RuntimeExceptions are programmer errors.

RuntimeExceptions are defined leading to an undefine state of the software.

Handling Ressources

(for instance Transactions)

If a ressource is used, the programmer has to ensure, that the ressource is freed afterwards.

If a transaction is used, the programmer has to ensure, that it is closed afterwards. Implementing this is easy within java. Please take the following snippet, which contains the basic elements of this strategy:

tid = kernelUtil.begin();
try {
  [...]
}
finally {
  kernelUtil.clear(tid);
}

(kernelUtil is an instance of the class EquipmentKernelUtil.)





Go to top   Edit this page   More info...   Attach file...
This page last changed on 24-Feb-2005 15:05:32 CET by OlafKrause .