Handling System Generated Exceptions

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

Handling System Generated Exceptions

Now that you know how to cause a system generated exception, you can learn how to handle it. In this example, a handler that is specifically designed to address divide-by-zero exceptions will simply output a message.

Code Sample:

Exception-Clause/Demos/exception_handled.sql
DECLARE
  x NUMBER;
BEGIN
  dbms_output.put_line('Starting...');
  x := 1 / 0;
  dbms_output.put_line('...Ending');
EXCEPTION
 WHEN ZERO_DIVIDE
  THEN DBMS_OUTPUT.PUT_LINE('Divide by zero error.');
END;

Code Explanation

Each PL/SQL block can optionally include an EXCEPTION section where specific exceptions and errors are captured and dealt with programmatically. Specific error types can be handled by indicating the error in a specific WHEN clause.

Next