Duration: 15 to 20 minutes.
- Create a procedure called "divide_by_zero".
- Declare two variables named x and y of type number. Assign x the value of one and y the value of zero.
- In the body of the procedure assign x the value of x divided by y. (This will result in a divide by zero error - expected for this exercise).
- Add a line that outputs We will not get here that demonstrates that the divide by zero exception raised in the previous
line will bypass the following lines.
- Add an exception section to handle the divide by zero error.
- Add a line to the exception section that outputs "USER MESSAGE: Error in: program unit name line line number".
- Add a line that prints out the call stack at the point the error occurred.
- Compile, run, and test and debug the procedure.
CREATE OR REPLACE PROCEDURE divide_by_zero
DBMS_OUTPUT.put_line('We will not get here.');
WHEN ZERO_DIVIDE THEN
DBMS_OUTPUT.put_line('USER MESSAGE: Error in: ' || $$PLSQL_UNIT
|| ' line ' || $$PLSQL_LINE);
-- Test it. Only the exception messages should be displayed.