Exceptions in Oracle
Exceptions in Oracle
Run-time errors can happen in declaration, execution, and exception PL/SQL blocks. The easiest to catch and handle are those errors thrown from an execution block because they are caught first by any local exception block and next by any containing block.
Syntax: WHEN {predefined_exception | user_defined_exception | OTHERS} THEN exception_handling_statement; [RETURN | EXIT ];
Function
SQLERRM
Oracle-Predefined Errors
Returns the defined error code and message for a raised exception if no number is passed to it.
User-Defined Errors
Returns a 1 and a UserDefined Exception message if triggered Returns the actual number parameter by the RAISE command. as a negative integer and a nonReturns Oracle exception message if a positive a valid integer in the range of number is passed to it or a negative negative 20001 to negative number that is not a predefined Oracle 20999 exception. and a text message set by the RAISE_APPLICATION_INFO Returns the actual number parameter function. as a negative integer and the Oracle defined message if a negative number for an Oracle-predefined exception is passed.
EXAMPLE
DECLARE a VARCHAR2(1); b VARCHAR2(2) := 'AB'; BEGIN a := b; EXCEPTION WHEN value_error THEN dbms_output.put_line('You can''t put ['||b||'] in a one character string.'); END; /