Home » SQL & PL/SQL » SQL & PL/SQL » begin end under exception (Oracle 9.2.0.3)
begin end under exception [message #405135] Tue, 26 May 2009 08:29 Go to next message
prachij593
Messages: 266
Registered: May 2009
Senior Member
Can we write a BEGIN EXCEPTION END; within exception block?
Re: begin end under exception [message #405137 is a reply to message #405135] Tue, 26 May 2009 08:32 Go to previous messageGo to next message
cookiemonster
Messages: 12404
Registered: September 2008
Location: Rainy Manchester
Senior Member
why don't you try it and find out?
Re: begin end under exception [message #405140 is a reply to message #405135] Tue, 26 May 2009 08:41 Go to previous messageGo to next message
ora_2007
Messages: 430
Registered: July 2007
Location: Mumbai
Senior Member
we can use it.......
below info will help you.
BEGIN
	  NULL; 
EXCEPTION
  WHEN OTHERS THEN 
	  BEGIN
	   	   	   NULL; 
	  EXCEPTION
	   		   WHEN OTHERS THEN 
	   		   NULL; 
	  END; 
END;  
Re: begin end under exception [message #405142 is a reply to message #405140] Tue, 26 May 2009 08:52 Go to previous messageGo to next message
prachij593
Messages: 266
Registered: May 2009
Senior Member
DECLARE
   a NUMBER;
   B NUMBER;
BEGIN
   SELECT dept_id
   INTO a 
   FROM dept 
   WHERE 1 = 2;
   EXCEPTION
   WHEN NO_DATA_FOUND 
   THEN
      BEGIN
         SELECT PRODUCT_ID
         INTO B 
         FROM PRODUCT 
         WHERE 1 = 2;
         EXCEPTION
         WHEN NO_DATA_FOUND 
         THEN
            DBMS_OUTPUT.PUT_LINE('D');
      END;
END;


[EDITED by LF: fixed [code] tags]

[Updated on: Wed, 27 May 2009 03:01] by Moderator

Report message to a moderator

Re: begin end under exception [message #405220 is a reply to message #405135] Wed, 27 May 2009 01:27 Go to previous messageGo to next message
ashoka_bl
Messages: 398
Registered: November 2006
Location: Bangalore
Senior Member

And what happened when u executed the block ? Did u get the results, I did and i got it as "D"

I am bit curious about this, why do want this ?
Re: begin end under exception [message #405225 is a reply to message #405220] Wed, 27 May 2009 02:07 Go to previous message
Frank
Messages: 7880
Registered: March 2000
Senior Member
ashoka_bl wrote on Wed, 27 May 2009 08:27
I am bit curious about this, why do want this ?

This is a very valid code-construct.
Often, the fact that an exception occurs is used explicitly in code. For example, insert and handle the DUP_VAL_ON_INDEX instead of first checking whether the duplicate already exists in the table.
Then is would be very legit to continue your code (which is inside the exceptionhandler) and handle any exceptions that occur there too.
Previous Topic: Getting all Linked rows
Next Topic: trigger problem
Goto Forum:
  


Current Time: Mon Dec 05 07:02:43 CST 2016

Total time taken to generate the page: 0.14806 seconds