In PL/SQL, a warning or error condition is called an exception. Certain exceptions can be predefined or they can be user defined. Predefined exceptions include division by zero or out of memory conditions.
Predefined exceptions have predefined names such as ZERO_DIVIDE and NO_DATA_FOUND.
When an error occurs, an exception is raised.
The exception is either handled by the system or user defined exception handlers.
The example below shows the structure of a simple exeception handler :
DECLARE
BEGIN
-- Start code
-- if an error occurs it will be handled
-- by the exception handler below
< CODE GOES HERE >
EXCEPTION WHEN OTHERS THEN
-- handle error
null;
END;
DECLARE
myException1 EXCEPTION;
myException2 EXCEPTION;
BEGIN
< CODE GOES HERE >
RAISE myException1;
< CODE GOES HERE >
RAISE myException2;
EXCEPTION
WHEN myException1 THEN
< CODE GOES HERE >
WHEN myException2 THEN
< CODE GOES HERE >
WHEN OTHERS THEN -- handles all other errors
< CODE GOES HERE >
END;