DMS Prac 23
DMS Prac 23
Experiment No 23
Title of Experiment Implement PL/SQL program based on Exception Handling (User-defined
exceptions)
exp1 EXCEPTION;
exp2 EXCEPTION;
BEGIN
IF y=0 then
raise exp1;
ELSEIF y > x then
raise exp2;
ELSE
div_r:= x / y;
Department of Computer Engineering : Academic Year 2024 – 2025
DATABASE MANAGEMENT SYSTEM (313315)
dbms_output.put_line('the result is '||div_r);
END IF;
EXCEPTION
WHEN exp1 THEN
dbms_output.put_line('Error');
dbms_output.put_line('division by zero not allowed');
WHEN exp2 THEN
dbms_output.put_line('Error');
dbms_output.put_line('y is greater than x please check the input');
END;
II. Procedure:
SET SERVEROUTPUT ON;
DECLARE
insufficient_funds EXCEPTION;
invalid_amount EXCEPTION;
BEGIN
deposit(500);
deposit(-100);
withdraw(300);
withdraw(1500);
withdraw(-200);
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('An unexpected error has occurred: ' ||
SQLERRM);
END;
III. Observations/Output:
Department of Computer Engineering : Academic Year 2024 – 2025
DATABASE MANAGEMENT SYSTEM (313315)
IV. Conclusion:
3. Robustness: The program checks for invalid inputs and insufficient funds,
providing informative error messages.
4. Flexibility: The structure allows for easy expansion to include more banking
operations.
V. Questions:
1. How to define the exception?
DECLARE
insufficient_funds EXCEPTION; -- User-defined exception
Department of Computer Engineering : Academic Year 2024 – 2025
DATABASE MANAGEMENT SYSTEM (313315)
EXCEPTION
WHEN insufficient_funds THEN
DBMS_OUTPUT.PUT_LINE('Error: Insufficient funds or invalid
withdrawal amount.');
END withdraw;
BEGIN
-- Test the withdraw procedure
withdraw(500); -- Valid withdrawal
withdraw(2000); -- Invalid withdrawal (insufficient funds)
withdraw(-100); -- Invalid withdrawal (negative amount)
END;
Dated signature
Marks Obtained
of Teacher
Process Product
Total (25)
Related (10) Related (15)