There have always been exceptions in programming. The first exception in any computer program was probably a divide-by-zero and at that time there was no mechanism to trap such an exception. A zero divide exception can be captured in PL/SQL with the following. This block prints the error when it occurs.
DECLARE n NUMBER; BEGIN n:= 2/0; EXCEPTION WHEN ZERO_DIVIDE THEN dbms_output.put_line('Caught a zero divide'); END;
The ZERO_DIVIDE is one of the PL/SQL built-in exceptions. The language has several predefined exceptions. We looked at DUP_VAL_ON_INDEX in Chapter 3. This exception is raised from a duplicate insert against a primary key or unique constraint. You can declare your own exceptions. These are called user-defined exceptions. ...