Causing System Generated Exceptions

Contact Us or call 1-877-932-8228
Causing System Generated Exceptions

Causing System Generated Exceptions

To gain a better understanding of how exceptions behave, you can explicitly cause an exception to occur by creating code that will compile but raise an exception at runtime.

Code Sample:

Exception-Clause/Demos/exception_caused.sql
DECLARE
  x NUMBER;
BEGIN
  dbms_output.put_line('Starting...');
  x := 1 / 0;
  dbms_output.put_line('...Ending');
END;

Code Explanation

In this example an error occurs because of an attempt to divide by zero:

ORA-01476: divisor is equal to zero

Oracle includes object names, numbers, and character strings in messages. When dealing with PL/SQL objects, a message stack includes additional information, such as the line number where the error occurred. In order to quickly track down errors, make sure to have line numbers displayed in your editor.

Next