10/3/2016
Exception Handling
By
Parteek Bhatia
Assistant Professor
Dept of Comp Sc & Engg
Thapar University
Patiala
Syntax Exception Types
EXCEPTION
There are two types of exceptions:
WHEN exception1 [OR exception2 ………] THEN statement1;
statement2; Implicitly raised exceptions
[WHEN exception3 [OR exception4 ………] THEN statement1;
statement2;
Explicitly raised exceptions
..…………..]
[WHEN OTHERS THEN
statement1;
statement2;
……..]
END;
Implicitly raised exceptions Some of Predefined Oracle Server
Predefined Oracle Server NO_DATA_FOUND
Non-predefined Oracle Server TOO_MANY_ROWS
DUP_VAL_ON_INDEX
ZERO_DIVIDE
INVALID_NUMBER
1
10/3/2016
Trapping of Non-predefined Oracle Server
To show use of User Defined System Exceptions
Syntax
Declare
Exception_name EXCEPTION;
PRAGMA EXCEPTION_INIT (exception_name, error_number);
Trapping of Explicitly raised or User Syntax
defined exceptions
Declare
Exception_name EXCEPTION;
Begin
...
If condition Then
RAISE exception_name;
End if;
…
Exception
When exception_name then
….
End;
2
10/3/2016
User defined exception Error Trapping Functions
Error Trapping Functions Error Trapping Functions
Thanks
Lets Implement it in Lab Session