currentException

The system variable SysLib.currentException identifies the exception that was thrown most recently in the run unit.

EGL provides a series of system exceptions to indicate the specific nature of a runtime problem. Each of these exceptions is a dictionary from which you can retrieve information, but your retrieval is always by way of the system variable SysLib.currentException (also a dictionary), which lets you access the exception thrown most recently in the run unit.

One field in any exception is code, which is a string that identifies the exception. You can determine the current exception by testing that field in logic like this:
  if (userRequest = "A")
    try
      add record1;
    onException
      case (SysLib.currentException.code)
        when (FileIOException)
          myErrorHandler(12);
        otherwise
          myErrorHandler(15);
      end
    end
  end

In this case, FileIOException is a constant, which is equivalent to the string value "com.ibm.egl.FileIOException". The EGL exception constant is always equivalent to the last qualifier in a string that begins "com.ibm.egl".

It is strongly recommended that you access the exception fields only in an onException block. The run unit terminates if your code accesses SysLib.currentException when no exception has occurred.

The next example accesses the field sqlcode in the exception SQLException:
  if (userRequest = "A")
    try
      add record01;
    onException
      case (SysLib.currentException.code)
        when ("com.ibm.egl.SQLException")
          if (SysLib.currentException.sqlcode == -270)
            myErrorHandler(16);
          else
            myErrorHandler(20);
          end
        otherwise
          myErrorHandler(15);
      end
    end
  end

Related concepts
Dictionary

Related reference
Exception handling
EGL library SysLib
EGL system exceptions

Feedback
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.