Посмотрите список Predefined Exceptions.
Если там нет исключения с нужным кодом (кода ошибки -2291
там нет), то есть две возможности:
begin
declare
integrity_constraint_violated exception ;
pragma exception_init (integrity_constraint_violated, -2291);
begin
raise integrity_constraint_violated;
exception when integrity_constraint_violated then
dbms_output.put_line ('exception integrity_constraint_violated catched');
raise;
end;
exception when others then
if sqlcode = -2291 then
dbms_output.put_line ('exception code -2291 catched');
end if;
raise;
end;
/
Результатом выполнения будет:
exception integrity_constraint_violated catched
exception code -2291 catched
ORA-02291: integrity constraint (.) violated - parent key not found
ORA-06512: at line 15
Заметьте, что нельзя записать, в какой таблице и какой ключ нарушен, т.е. вот это (.)
.
Это могут только внутренние функции БД, которые проверяют ограничение.