|
Transactions and Savepoints | SQL Language in 602SQL | System Objects |
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.
Exception situations can be divided in three groups:
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.
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).
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:
Transactions and Savepoints | SQL Language in 602SQL | System Objects |