Subject Error Trapping in Procedures
Author Epstein, Ed
I currently have a procedure that has 6 passed parameters. I am evaluating
all 6 of these parameters to determine if they qualify for the process. If
they do not, they get added to an error table. No exceptions were thrown.
The purpose of this was to keep all error handling on the backend and
completly away from the front end. All the errors would automatically be
recorded in another table.

This only works for about 90% of the records being processed. I have run
into certain SQLCode errors that are not being caught by my evaluation
routines. They are causing exceptions to be thrown and consequently the
records are not being added to the error table.

I rewrote the procedure to throw an exception after it inserts a record into
the error table. I then put in:

When Any Do
Begin
If (Already_Inserted = 0) Then
Begin
INSERT INTO ERROR(blah,blah,blah,error_code) Values(blah,blah,blah,9);
END
End

This catches all the exceptions thrown and if its an exception not handled
by my own eval routines, it puts in an error into the table. This is all
being done successfully.

My problem is that I want to be able to further refine the exceptions that
are not originating from my own code.
As an example:
Violation of Unique Key Constraints -83 or -830
Overflow during data type conversion -413

All of these are now being wrapped up in one general error code. I really
need at least the duplicate record to be separated. Inside the WHEN ANY code
I cannot seem to evaulate the SQLCODE. Is there any way around this?


[Non-text portions of this message have been removed]