The interactions in this eCourse require Javascript to be enabled.
Handling Exceptions: Part 3
previous|next
Example
CREATE OR REPLACE PROCEDURE raise_salary (p_id IN employees.employee_id%TYPE, p_percent IN NUMBER)IS e_toomuch EXCEPTION;BEGIN IF p_percent >= .30 THEN RAISE e_toomuch; END IF; UPDATE employees SET salary = salary * (1 + p_percent/100) WHERE employee_id = p_id; EXCEPTION WHEN e_toomuch THEN dbms_output.put_line('Amount is too high.'); WHEN OTHERS THEN dbms_output.put_line('Error: raise not processed.');END raise_salary;/
The exception is defined in the declarative section. If the raise amount passed into the procedure is greater than .30 (30%), then the error is raised and control of the program passes the the EXCEPTION area. The EXCEPTION section checks for the error type. If the error raised is e_toomuch, a customized message is displayed. The OTHERS clause catches for any other exceptions that may occur in this PL/SQL block.