602SQL Documentation Index  

Processing Errors and Exceptions in SQL

An error is a state that is impossible to proceed in normal operation. The 602SQL Server has a default reaction for each error. This reaction is used if the application does not have a method of handling this error specified. The server may terminate the operation, rollback the transaction or send a message to the client.

The database application author may specify what should happen if an error occurs (by the error handler). The handler may either be local (respond only to errors that occur in the block where the handler is declared) or global (respond to all errors in the schema).

See also Errors and Error Categorization.

Error and Exception Categories

Exception situations can be divided in three groups:

  1. Server errors.
  2. Exceptions declared by a user in the CONDITION declaration and marked with an identifier. These exceptions occur when the SIGNAL statement is explicitly executed in a program. These exceptions are used to abort a sequence of statements, begin/end blocks or routines.
  3. Exceptions declared by a user in the CONDITION declaration, marked with an identifier and assigned to a certain error. These exceptions occur when the particular error state occurs when processing a client request, or when explicitly called from the SIGNAL statement.

You can control some server errors (#1 above) and all user defined errors that are not connected to a server error (#2 above) using a handler. The third type of exceptions (#3 above) can only be handled if the errors assigned to them can be handled.

Error Definition

The SQL standard defines errors using a string of 5 alphanumeric characters, called a SQLSTATE. The SQLSTATE is specified in the error handler declaration and may be specified in the exception declaration.

The 602SQL Server internally assigns positive integer numbers to errors. Server errors that are not assigned a SQLSTATE will be composed of the letter W and a 4-digit number (e.g. An error with the number 152 is assigned SQLSTATE "W0152". This allows you to define handlers for 602SQL specific errors).

Handling Exceptions and Errors

When an error or exception occurs, the system searches for a handler. A handler is assigned either to a particular error (or exceptions) or a group of exceptions in the declaration. The search method for a handler will begin from the place where the error occurred forward. If a handler is found, it is executed and further statement execution may be allowed (depending on the handler type).

If an exception occurs when running handler 'H' that is not processed in the handler, no handler defined on the same level as handler 'H' will be used for processing this exception, only the handler defined outside will be used.

You can use the RESIGNAL statement when inside a handler. This will transfer the error or exception processed by this handler to the outside handler.

List of topics: