You will encounter several kinds of errors and warnings when working with PL/SQL program units:
1. Compilation errors: your programs will not compile. The errors reported by the PL/SQL compiler are of the form "PLS-NNNN: message".
2. Compile-time warnings: While compiling stored PL/SQL units, the PL/SQL compiler generates warnings for conditions that are not serious enough to cause errors and prevent compilation—for example, using a deprecated PL/SQL feature. Warnings take the form "PLW-NNNN: message".
3. Run-time errors: you (or your users) run your program and an error (known as an exception) is raised. Run-time errors generally take the form "ORA-NNNN: message".
You can write an exception handler in a PL/SQL block to trap and handle run-time errors.
The PL/SQL run-time engine will raise exceptions whenever the Oracle database detects a problem or it executes a RAISE or RAISE_APPLICATION_ERROR statement in your code. You can then trap or handle these exceptions in the exception section - or let the exception propagate unhandled to the enclosing block or host environment.
Oracle PL/SQL offers three (as of 12.1) built-in functions to retrieve the error message associated with the currently-raised exception: SQLERRM, DBMS_UTILITY.FORMAT_ERROR_STACK and UTL_CALL_STACK.ERROR_MSG.
If passed no argument (error code), SQLERRM returns the message associated with the currently-raised exception (it can also return a stack of such messages).
DBMS_UTILITY.FORMAT_ERROR_STACK returns the same thing, but supports longer strings; SQLERRM will truncate at around 500 characters (which can happen when you have a stack of errors).
Added in 12.1, UTL_CALL_STACK.ERROR_MSG is part of an clean, simple API to both call stack, error stack and backtrace information.