ExceptionsExceptions
Exception handling in a multi-language application
Home > Books > Solutions Developer Guide > Scripting Languages > Exceptions

Rate this page:
Really useful
Satisfactory
Not helpful
Confusing
Incorrect
Unsure
Extra comments:


Handling Exceptions

In the NetKernel resource-oriented computing model language runtimes are services. As explored in the general discussion about exception handling NetKernel is capable of propagating an exception raised in one language to a handler in another language.

While the specifics about raising and handling an exception is covered in the documentation about each scripting language we briefly discuss the basis for NetKernel exception handling. NetKernel exceptions have a physical representation com.ten60.netkernel.util.NetKernelException. An elided view of the class follows:

package com.ten60.netkernel.util;
import java.io.*;
import java.util.*;

public class NetKernelException
  extends    java.lang.Exception
  implements IXMLException
{ ...
  /**
   * Constructs an instance of  with the specified detail message.
   * @param aMessage the detail message.
   */
  public NetKernelException(String aMessage)
  { super(aMessage);
  }

  /**
   * Constructs an instance of  with the specified Id,
   * detail message, and request id.
   * @param aId an id for the exception
   * @param aMessage the detail message.
   * @param aRequestId id of request that caused the exception
   */
  public NetKernelException(String aId, String aMessage, String aRequestId)
  { ...
  }

  /** @Return the id for the exception
   */
  public String getId()
  { ...
  }

  /** Adds an exception cause to this exception
   */
  public void addCause(Throwable aThrowable)
  { ...
  }

  ...

  /** Recursively output the state of this exception and its
   *  causes to the given writer
   */
  public void appendXML(Writer aWriter) throws IOException
  { ...
  }

  ...

  /** return XML representation of recursive exception
   *  pretty-printed with indent
   */
  public String toString()
  { ...
  }
}

To throw an exception code should instantiate an object of the class NetKernelException, set an ID to indicate the type of exception and optionally include an descriptive information and cause (as a Java Throwable). To handle a NetKernel exception, construct an exception handler (Java catch block) and trap NetKernelException.

It is important not to directly handle errors such as OutOfMemoryError and ThreadDeath as the NetKernel kernel has special handling for these. If catching all Exceptions use a catch block with java.lang.Exception rather than javalang.Throwable.

© 2003-2007, 1060 Research Limited. 1060 registered trademark, NetKernel trademark of 1060 Research Limited.