InterBase PSQL language has had support for WHEN ANY ... for a long time. See https://docwiki.embarcadero.com/InterBase/2020/en/Handling_Errors and https://docwiki.embarcadero.com/InterBase/2020/en/Examples_of_Error_Behavior_and_Handling
Where it seems to be limited is that it does not recognize SQLCODE as a context variable that you can get a value from for assignment in your code within the WHEN ANY block. It would be a useful enhancement, I agree.
As a sample, the following code works in InterBase, albeit not knowing the exact SQLCODE generated. But, you can catch ANY exception in InterBase PSQL as well.
set echo on;
/* run some bad statements; see exception code(s) */
/* Expected exception: SQLCODE -413 */
insert into employee (emp_no, first_name, last_name, dept_no, job_code, job_grade, job_country, salary)
values (2000, 'Two', 'Thousand', 2000, 'SALES', 2000, 'USA', 1);
/* Expected exception: SQLCODE -297 */
insert into employee (emp_no, first_name, last_name, dept_no, job_code, job_grade, job_country, salary)
values (2000, 'Two', 'Thousand', 'ABC', 'SALES', 2000, 'USA', 1);
rollback;
/* Now, do the same with procedures. */
drop procedure TEST_PROC;
COMMIT;
set term ^;
CREATE PROCEDURE TEST_PROC (runcase INTEGER)
RETURNS (N_ERROR INTEGER)
AS
begin
n_error=0;
begin
/* Give bad DEPT_NO value; integral instead of CHAR(3) */
/* Expected exception: SQLCODE -413 */
if (:runcase = 1) then
insert into employee (emp_no, first_name, last_name, dept_no, job_code, job_grade, job_country, salary)
values (2000, 'Two', 'Thousand', 2000, 'SALES', 2000, 'USA', 1);
/* Give bad SALARY value violating a value constraint */
/* Expected exception: SQLCODE -297 */
if (:runcase = 2) then
insert into employee (emp_no, first_name, last_name, dept_no, job_code, job_grade, job_country, salary)
values (2000, 'Two', 'Thousand', 'ABC', 'SALES', 2000, 'USA', 1);
/* good SQL that will succeed; no exception */
if (:runcase = 3) then
INSERT INTO country (country, currency) VALUES ('India', 'Rupee');
/* check for errors */
when any do begin
n_error = :runcase;
exit;
end
end
end^
set term ;^
commit;
/* Now test above procedures */
/* see if any work getting done below, by setting count option on */
set count on;
execute procedure test_proc (1);
rollback;
execute procedure test_proc (2);
rollback;
execute procedure test_proc (3);
select * from country where country='India';
rollback;
execute procedure test_proc (99);
rollback;