0% found this document useful (0 votes)
29 views16 pages

Exceptions

The document discusses exceptions in PL/SQL including system-defined exceptions like VALUE_ERROR and ZERO_DIVIDE as well as user-defined exceptions that can be raised using RAISE_APPLICATION_ERROR. Exceptions allow programmers to catch error conditions during program execution and take appropriate action through an EXCEPTION block.

Uploaded by

Krishna Vineeth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views16 pages

Exceptions

The document discusses exceptions in PL/SQL including system-defined exceptions like VALUE_ERROR and ZERO_DIVIDE as well as user-defined exceptions that can be raised using RAISE_APPLICATION_ERROR. Exceptions allow programmers to catch error conditions during program execution and take appropriate action through an EXCEPTION block.

Uploaded by

Krishna Vineeth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Exceptions

EXCEPTION
• An exception is an error condition during a
program execution. PL/SQL supports
programmers to catch such conditions
using EXCEPTION block in the program and an
appropriate action is taken against the error
condition. There are two types of exceptions −
• System-defined exceptions
• User-defined exceptions
When other keyword should be used only at the end of
the exception handling block as no exception handling
part present later will get executed as the control will
exit from the block after executing the WHEN
OTHERS.
1.System defined exceptions:
These exceptions are predefined in PL/SQL which
get raised WHEN certain database rule is violated.
System-defined exceptions are further divided into
two categories:Named system exceptions.
2.Unnamed system exceptions.
VALUE_ERROR:This error is raised WHEN a
statement is executed that resulted in an arithmetic,
numeric, string, conversion, or constraint error. This
error mainly results from programmer error or invalid
data input
ZERO_DIVIDE = raises exception WHEN dividing
with zero
DECLARE
a int:=10;
b int:=0;
c int;

BEGIN
c:=a/b;
dbms_output.put_line('the result after division is'||c);

exception
WHEN zero_divide THEN
dbms_output.put_line('dividing by zero please check the values again');
dbms_output.put_line('the value of a is '||a);
dbms_output.put_line('the value of b is '||b);
END;
RAISE_APPLICATION_ERROR
It is used to display user-defined error messages with
error number whose range is in between -20000 and
-20999. When RAISE_APPLICATION_ERROR
executes it returns error message and error code which
looks same as Oracle built-in error.
DECLARE
ui EXCEPTION;
n NUMBER :=10;

BEGIN
FOR i IN 1..n LOOP
dbms_output.put_line(i*i);
IF i*i=36 THEN
RAISE ui;
END IF;
END LOOP;

EXCEPTION
WHEN ui THEN
RAISE_APPLICATION_ERROR(-20015, 'Welcome to myclass');

END;
• Advantages:
• Exception handling is very useful for error handling,
without it we have to issue the command at every
point to check for execution errors:
• With exception handling we handle errors without
writing statements multiple times and we can even
handle dIFferent types of errors in one exception
block:

You might also like