------------------------------------------------------------------------------------------ -- Creating and raising a custom exception -- with error code and error message ------------------------------------------------------------------------------------------ CREATE or replace PROCEDURE weekend_work(p_date date) AS BEGIN IF to_char(p_date,'DY') in ('SAT','SUN') THEN -- RAISE_APPLICATION_ERROR(-20123, 'No work allowed on weekend'); -- custom exception END IF; END; / ------------------------------------------------------------------------------------------ -- Creating and raising a custom exception -- with error code and error message ------------------------------------------------------------------------------------------ CREATE or replace PROCEDURE working_day(p_date date) AS x_weekend_work exception; -- declaring an exception -- PRAGMA EXCEPTION_INIT(x_weekend_work, -20123); -- assigning it to the code -- -- raised above BEGIN -- some code... weekend_work(p_date); -- call procedure above dbms_output.put_line('Work Day is OK'); -- EXCEPTION when x_weekend_work then -- handle the exception dbms_output.put_line('Invalid Work Day ' || sqlerrm); -- when others then if sqlcode = -12345 then dbms_output.put_line('Some message'); elsif sqlcode = -12346 then dbms_output.put_line('Some other message'); elsif sqlcode = -12347 then dbms_output.put_line('Some other message2'); end if; END; / CALL working_day(sysdate)