Reference Guide > TDV SQL Script > SQL Language Concepts > Attributes of CURRENT_EXCEPTION
 
Attributes of CURRENT_EXCEPTION
In SQL Script, you can obtain the attributes of an exception while within the exception handler.
For details, also see:
SQL Script Exceptions
Raising and Handling Exceptions
External Exceptions
DECLARE EXCEPTION
Syntax
CURRENT_EXCEPTION.<attribute>
Remarks
The following table describes cursor exception attributes.
Attribute
Description
NAME
A string that is the exception’s name. This name is fully qualified, as follows:
/ns1/ns2/procedure.s1.s2.exceptionName
The ns1 and ns2 are namespace elements of the path. The s1 and s2 are compound statement blocks and are either named according to the label on that block or as unnamed# where # is an integer value.
ID
An integer that is the exception’s system ID. All user exceptions have the ID -1 (negative one). System exceptions all have unique IDs.
MESSAGE
The VARCHAR(255) value defined for the current exception. If no value is defined for the exception, then this attribute is NULL.
TRACE
The VARCHAR(32768) value defined contains the exception stack trace as a string.
If the exception handler includes a compound statement, CURRENT_EXCEPTION within the BEGIN portion refers to the current exception of the parent scope, but within the exception handler portion of the child scope CURRENT_EXCEPTION refers to the local exception and there is no way to access the parent exception. For details, see Compound Statements.
Example
PROCEDURE p (IN x INTEGER, OUT result VARCHAR)
BEGIN
  CALL /shared/f(x);
EXCEPTION
  ELSE
    IF CURRENT_EXCEPTION.MESSAGE IS NOT NULL THEN
      SET result = CURRENT_EXCEPTION.MESSAGE;
    ELSE
      SET result = CURRENT_EXCEPTION.NAME;
  END
END
 
MESSAGE:      'x must be > 0. x = -123'
NAME:             '/shared/f.illegal_arg_ex'
SQL Script Exceptions
The following is a list of SQL Script exceptions that can be thrown. The message that is passed is left to the author of the SQL Script.
Exception Message
Description
CannotExecuteSelectException
An attempt is made to execute a SELECT statement. SELECT statements are opened, not executed. INSERT, UPDATE, and DELETE statements are executed.
CannotOpenCursorException
An attempt is made to open a cursor that is either a NULL reference variable, or is a cursor that is not defined within the current procedure that has already been closed.
CannotOpenNonSelectException
An attempt is made to open an INSERT, UPDATE, or DELETE statement. INSERT, UPDATE, and DELETE statements are executed, not opened. SELECT statements are opened.
CursorAlreadyOpenException
An attempt is made to open a cursor that is already open.
CursorNotOpenException
An attempt is made to fetch from or to close a cursor that is closed, or to insert into or close a PIPE that is closed.
CursorTypeMismatchException
An attempt is made to open a cursor using dynamic SQL and the projections from the SQL do not match the cursor’s type definition.
DuplicateNameException
An attempt is made to name something and that name is already in use.
EvaluationException
An error is encountered evaluating an expression.
IllegalArgumentException
An argument is passed into a procedure with an illegal value.
IllegalStateException
A procedure cannot perform its task due to some unexpected state.
NotAllowedException
An attempt is made to perform a task that is not allowed due to policy restrictions or other limitations.
NotFoundException
An attempt is made to use a resource or other item that does not exist.
NotSupportedException
An attempt is made to use a feature that is not supported.
NullVariableException
An attempt is made to access a data member of a NULL variable. For example, to access a data member of a ROW variable that is currently NULL.
ParseException
A dynamic SQL statement fails to parse or resolve correctly. This can be due to a syntax error or a reference to a nonexistent column, table, procedure, or function.
PipeNotOpenException
An attempt is made to insert into or to close a PIPE that is already closed.
ProcedureClosedException
A procedure is closed forcibly by the system due to being aborted by the caller or an administrator.
ProtocolException
A task fails due to a processing error on a data protocol.
SecurityException
An attempt is made to perform an action without proper privileges.
SystemException
A general failure in the runtime is encountered
TransactionClosedException
An attempt is made to perform a transactional task (such as fetching from a cursor) after the transaction has been committed or rolled back.
TransactionFailureException
A transaction failure occurs.
UnexpectedRowCountException
A cursor has an unexpected number of rows returned. For example, the SELECT INTO statement requires the cursor to return exactly one row.
UnopenedCursorReturnedException
An unopened cursor is returned from a procedure. Cursors must be NULL or be open when returned.
SOAPFaultException
A SOAP Fault is returned from a Web service.