Handling Exceptions Assignment Help

Assignment Help: >> User-Defined Exceptions - Handling Exceptions

Handling Exceptions:

It must be handled after the exception is raised. Handling of exceptions is performed using the exception handling section same to handling of pre-defined exceptions.

WHEN ex1 THEN

......

The following example describes this:

Example

DECLARE

Ex1 EXCEPTION;

N NUMBER(5):=&x;

BEGIN

If N > 20000 THEN

RAISE ex1;

END IF;

EXCEPTION

WHEN ex1 THEN

DBMS_OUTPUT.PUT_LINE('Value must not exceed 20000');

END;

Let's consider another example. The subsequent example adds the accepted value onto the table. If the salary exceeds from 30000 the exception SALARY_RAISE is raised and handled.

DECLARE

ENO NUMBER:=&NO;

NAME VARCHAR2(20):='&B';

SALARY NUMBER:=&P;

SALARY_RAISE EXCEPTION;

BEGIN

IF SALARY > 30000 THEN

RAISE SALARY_RAISE;

ELSE

INSERT INTO EMP(EMPNO,ENAME,SAL) VALUES(ENO,NAME,SALARY);

END IF;

EXCEPTION

WHEN SALARY_RAISE THEN

DBMS_OUTPUT.PUT_LINE('SALARY EXCEEDS 30000');

END;

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd