Explain exception handling with its two types.

Exception Handling: Exception is nothing but an error. Exception can be raise when DBMS encounters errors or it can be raised explicitly. When the system throws a warning or has an error it can lead to an exception. Such exception needs to be handled and can be defined internally or user defined. Exception handling is nothing but a code block in memory that will attempt to resolve current error condition. 

Syntax: 
DECLARE 
; Declaration section 
…executable statement;
 EXCEPTION
WHEN ex_name1 THEN
; Error handling statements/user defined action to be carried out;
 END; 

Types of Exception:
1) Predefined Exception/system defined exception/named exception: Are always automatically raised whenever related error occurs. The most common errors that can occur during the execution of PL/SQL. Not declared explicitly i.e. cursor already open, invalid cursor, no data found, zero divide and too many rows etc. Programs are handled by system defined Exceptions. 

2) User defined exception:
 It must be declare by the user in the declaration part of the block where the exception is used. It is raised explicitly in sequence of statements using:  
Raise_application_error(Exception_Number, Error_Message);

Post a Comment

0 Comments