Oracle User-Defined Exception

Submitted by:Jhon Smith

Date added:20 April, 2013

Category:PL SQL

You can create your own Exceptions in PL/SQL

Tags: exceptions

Code Snippet:

    -- User-defined Exception.
DECLARE
user_defined_exception EXCEPTION;
BEGIN
RAISE user_defined_exception;
EXCEPTION
WHEN user_defined_exception THEN
DBMS_OUTPUT.PUT_LINE(SQLERRM); -- Gives "User-Defined Exception".
END;
/


-- User-defined Exception with a user-defined error message.

DECLARE
user_defined_exception EXCEPTION;
PRAGMA EXCEPTION_INIT( user_defined_exception, -20001 );
BEGIN
raise_application_error( -20001, 'This is a user defined error' );
EXCEPTION
WHEN user_defined_exception THEN
DBMS_OUTPUT.PUT_LINE( SQLERRM );
END;
/
 
 

Comments