The error which occurs when a check constraint is violated is ORA-02290. Although there is no "standard" definition for this it's easy enough to declare your own exception so you can catch the -2290 when it's thrown. Let's say we have a table created as follows:
CREATE TABLE SOME_TABLE (COL1 CHAR(1) CHECK(COL1 IN ('Y', 'N')));
and that we then run the following block:
DECLARE
-- First, declare and initialize an appropriate exception
CHECK_CONSTRAINT_VIOLATED EXCEPTION;
PRAGMA EXCEPTION_INIT(CHECK_CONSTRAINT_VIOLATED, -2290);
BEGIN
INSERT INTO SOME_TABLE(COL1) VALUES ('X'); -- will violate the check constraint
RETURN;
EXCEPTION
WHEN CHECK_CONSTRAINT_VIOLATED THEN -- catch the ORA-02290 exception
DBMS_OUTPUT.PUT_LINE('INSERT failed due to check constraint violation');
WHEN OTHERS THEN -- catch all other exceptions
DBMS_OUTPUT.PUT_LINE('Something else went wrong - ' || SQLCODE ||
' : ' || SQLERRM);
END;
If you create the table as shown earlier and then run the block above you'll find that the line 'INSERT failed due to check constraint violation' will show up on DBMS_OUTPUT.
Share and enjoy.