473,470 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

EXCEPTIONS - 2

debasisdas
8,127 Recognized Expert Expert
Sample Example Of Zero_divide
===============================
Expand|Select|Wrap|Line Numbers
  1. Declare
  2. I Int:=&i;
  3. J Int:=&j;
  4. K Int;
  5. Begin
  6. K:=i/j;
  7. Dbms_output.put_line(k);
  8. Exception
  9. --if j=0 then (dividng the number by zero)
  10. When Zero_divide Then
  11. Raise_application_error(-20002,'cant Divide By Zero.....!');
  12. When Others Then
  13. Raise_application_error(-20003,'some Other Error........!');
  14. End;
  15.  
Zero_divide----This exception is raised when in any number id divided by zero in arithmetic operations.

Sample Example Of No_data_found
==============================
Expand|Select|Wrap|Line Numbers
  1. Declare
  2. Name Varchar2(20);
  3. No Int:=&no;
  4. Begin
  5. Select Ename Into Name From Emp Where Empno=no;
  6. Dbms_output.put_line(name);
  7. Exception
  8. When No_data_found Then
  9. Raise_application_error(-20002,'no Data Is Found For This Record.....!');
  10. When Others Then
  11. Raise_application_error(-20003,'some Other Error........!');
  12. End;
  13.  
No_data_found---This exception is raised whan any select into statment fails to retrive any data from database table. This may create eror in further data processing if left unhandled.

sample example of invalid_cursor
=============================
Expand|Select|Wrap|Line Numbers
  1. DECLARE
  2. CURSOR c1 IS SELECT ename FROM emp WHERE ROWNUM < 11;
  3. name emp.ename%TYPE;
  4. BEGIN
  5. OPEN c1;
  6. LOOP
  7. FETCH c1 INTO name;
  8. EXIT WHEN c1%NOTFOUND;
  9. dbms_output.put_line(c1%ROWCOUNT || '. ' || name);
  10. END LOOP;
  11. --cursor is closed
  12. CLOSE c1;
  13. --again trying to access the cursor variable after cursor is closed ,which raises an exception
  14. dbms_output.put_line(c1%ROWCOUNT); 
  15. exception
  16. when invalid_cursor then
  17. raise_application_error(-20001,'invalid operation in cursor');
  18. END;
  19.  
invalid_cursor--This explanation is self explanatory. Raises if there is any invalid cursor related operations.
Note --In the above example ,it raise the exception because the program tries to access the cursor variable %ROWCOUNT after the cursor is closed.

Sample Example Of DUP_VAL_ON_INDEX
==================================
Expand|Select|Wrap|Line Numbers
  1. create procedure insdept(num  number,name varchar2)
  2. is
  3. begin
  4. insert into dept(deptno,dname) values (num,name);
  5. commit;
  6. dbms_output.put_line('One row inserted...!');
  7. exception
  8. when dup_val_on_index then
  9. raise_application_error(-20001,'duplicate entry...!');
  10. when others then
  11. raise_application_error(-20002,'some other error occured...!');
  12. end;
  13.  
DUP_VAL_ON_INDEX-----This Exception is raised if a duplicate value is inserted on a primary key / unique field . Used to maintain data integrity.


Sample example showing TOO_MANY_ROWS
==================================
Expand|Select|Wrap|Line Numbers
  1. declare
  2. name varchar2(20);
  3. begin
  4. select ename into name from emp where deptno=&deptnumber;
  5. dbms_output.put_line(name);
  6. exception
  7. when NO_DATA_FOUND then
  8. raise_application_error(-20001,'no such data found...1');
  9. when TOO_MANY_ROWS then
  10. raise_application_error(-20002,'more than one matching record found...!');
  11. when OTHERS then
  12. raise_application_error(-20003,'some unexpected error occured...!');
  13. end;
  14.  
  15.  
TOO_MANY_ROWS---This exception is raised when more data is selected than that can be stored in the target variable in a select into statment.


Also check EXCEPTIONS - 3
Jun 2 '07 #1
0 3878

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: David Turner | last post by:
Hi all I noticed something interesting while testing some RAII concepts ported from C++ in Python. I haven't managed to find any information about it on the web, hence this post. The problem...
21
by: dkcpub | last post by:
I'm very new to Python, but I couldn't find anything in the docs or faq about this. And I fished around in the IDLE menus but didn't see anything. Is there a tool that can determine all the...
26
by: OvErboRed | last post by:
I just read a whole bunch of threads on microsoft.public.dotnet.* regarding checked exceptions (the longest-running of which seems to be <cJQQ9.4419 $j94.834878@news02.tsnz.net>. My personal...
9
by: Gianni Mariani | last post by:
I'm involved in a new project and a new member on the team has voiced a strong opinion that we should utilize exceptions. The other members on the team indicate that they have either been burned...
6
by: RepStat | last post by:
I've read that it is best not to use exceptions willy-nilly for stupid purposes as they can be a major performance hit if they are thrown. But is it a performance hit to use a try..catch..finally...
14
by: dcassar | last post by:
I have had a lively discussion with some coworkers and decided to get some general feedback on an issue that I could find very little guidance on. Why is it considered bad practice to define a...
8
by: cat | last post by:
I had a long and heated discussion with other developers on my team on when it makes sense to throw an exception and when to use an alternate solution. The .NET documentation recommends that an...
1
by: Anonieko | last post by:
Understanding and Using Exceptions (this is a really long post...only read it if you (a) don't know what try/catch is OR (b) actually write catch(Exception ex) or catch{ }) The first thing I...
2
by: Zytan | last post by:
I know that WebRequest.GetResponse can throw WebException from internet tutorials. However in the MSDN docs: http://msdn2.microsoft.com/en-us/library/system.net.webrequest.getresponse.aspx It...
0
RedSon
by: RedSon | last post by:
Chapter 3: What are the most common Exceptions and what do they mean? As we saw in the last chapter, there isn't only the standard Exception, but you also get special exceptions like...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.