JavaRegisterException Function

Action

Registers a Java exception string under a custom error number. This error number can later be used to specify a custom severity for the exception. See also ErrorAdd function.

Note It is possible to register several exception messages to one error number.

Include file

Java.bdh

Syntax

JavaRegisterException( in nErrNumber    : number,
                       in sExceptionMsg : string,
                       in nFlag         : number optional ): boolean;

Return value

  • true if exception message could be registered und the specified error number

  • false otherwise

Parameter Description
nErrNumber Error number of exception to register.
sExceptionMsg Exception message to register.
nFlag

By passing one of the following parameters to the function, it is possible to determine when an exception raises an error:

  • JAVA_OPTION_MATCH_EXACT: The text of the raised exception must be equal to sExceptionMsg.

  • JAVA_OPTION_MATCH_SUBSTRING: The text of the raised exception must contain sExceptionMsg.

If no parameter is specified then the function is using JAVA_OPTION_MATCH_EXACT per default.

Example

var
  hTestObj    : number; 

dcltrans
  transaction TInit
  begin
    JavaCreateJavaVM();
    hTestObj := JavaLoadObject("TestClass");
  end TInit;

  transaction TException
  var   
    sBuffer : string;
    bRetVal : boolean;
  begin
    JavaRegisterException(500, "java.lang.RuntimeException");
    ErrorAdd(FACILITY_NATIVE_JAVA, 500, SEVERITY_INFORMATIONAL);
    bRetVal := JavaCallMethod(hTestObj, "doException");
    JavaGetLastException(hTestObj, sBuffer);

    if not bRetVal then
      Print(sBuffer);
    end;
  end TException;