| Exception Handling [message #560704] |
Mon, 16 July 2012 08:38  |
|
|
Hi all,
Is it possible to take execution control back from exception handling section to Execution statement?.. If Yes then How?..
|
|
|
|
|
|
|
|
|
|
| Re: Exception Handling [message #560728 is a reply to message #560708] |
Mon, 16 July 2012 09:43   |
mnitu
Messages: 136 Registered: February 2008 Location: Reims
|
Senior Member |
|
|
amitsukte wrote on Mon, 16 July 2012 15:49... Again is it possible to take execution control back to statement 2 from the Exception of statement2?..
Yes it is, but it's so unusual that one make ask why you are trying to do this? What are trying to do?
|
|
|
|
|
|
|
|
|
|
| Re: Exception Handling [message #560744 is a reply to message #560742] |
Mon, 16 July 2012 11:19   |
ThomasG
Messages: 2892 Registered: April 2005 Location: Heilbronn, Germany
|
Senior Member |
|
|
[quote title=dariyoosh wrote on Mon, 16 July 2012 17:52]Michel Cadot wrote on Mon, 16 July 2012 17:20Quote:What are trying to do?
This is the good question, what is the end Now one may want to put this inside a loop and block the program by an endless loop until the user specifies a valid option.
Except it doesn't work that way. The PL/SQL block is executed on the server as a whole, there is no way to have a loop "until the user specifies a valid option", since there is no way so have any user-interaction once the loop has started. So the "try again" must be something that can happen without user interaction.
One thing where it could make sense would be something that is done over an unreliable network connection and a "try it 10 times with a pause in between" approach is taken.
|
|
|
|
|
|
|
|
| Re: Exception Handling [message #560747 is a reply to message #560745] |
Mon, 16 July 2012 11:44   |
 |
Michel Cadot
Messages: 54672 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
dariyoosh wrote on Mon, 16 July 2012 18:28Michel Cadot wrote on Mon, 16 July 2012 18:18This is a very very bad code, unmaintanable, ununderstandable.
I never said that this is perfect , I just wanted to show him that it is possible to take the control back to the original block, so what I provided was just a piece of code not a complete program where all exceptions are handeled according to best practice.
But what you show is not understandable, I read the code and I can't know what you want to do, it is like a plate of spaghetti.
NEVER post bad code in forum, it will be copied, for sure it will be.
Regards
Michel
|
|
|
|
| Re: Exception Handling [message #560749 is a reply to message #560708] |
Mon, 16 July 2012 12:20   |
Solomon Yakobson
Messages: 1442 Registered: January 2010
|
Senior Member |
|
|
amitsukte wrote on Mon, 16 July 2012 09:49Thanks Michel.. Again is it possible to take execution control back to statement 2 from the Exception of statement2?..
Yes, it is possible:
DECLARE
...
BEGIN
statement1;
LOOP
BEGIN
statement2;
EXIT;
EXCEPTION
WHEN OTHERS
THEN
... -- analyze exception and fix the cause
... -- you'll end up in an infinite loop
... -- if you do not fix the cause
END;
END LOOP;
...
END;
/
SY.
|
|
|
|
|
|
|
|
|
|
|
|
| Re: Exception Handling [message #560788 is a reply to message #560756] |
Tue, 17 July 2012 02:50   |
mnitu
Messages: 136 Registered: February 2008 Location: Reims
|
Senior Member |
|
|
Solomon Yakobson wrote on Mon, 16 July 2012 20:38
...So since I am a lazy bum I created a script that checks for resource busy exception, sleeps for N seconds (I pass N as parameter) and issues statement again and again till it is done....
Lock table in exclusive mode will do that.
|
|
|
|
|
|
| Re: Exception Handling [message #560817 is a reply to message #560756] |
Tue, 17 July 2012 05:00   |
John Watson
Messages: 3174 Registered: January 2010 Location: Global Village
|
Senior Member |
|
|
Quote:Ever ran into a situation where in 7x24 environment you need to issue DDL on an in-use object and get resource busy exception? A solution that can work for this is ALTER SYSTEM QUIESCE RESTRICTED. You can usually get the brief moment of peace-and-quiet you need with a very short quiesce that users won't notice. You do need EE licences of course, as it is implemented with the Resource Manager.
|
|
|
|
| Re: Exception Handling [message #560826 is a reply to message #560771] |
Tue, 17 July 2012 05:34   |
Solomon Yakobson
Messages: 1442 Registered: January 2010
|
Senior Member |
|
|
Michel Cadot wrote on Tue, 17 July 2012 02:06How do you handle 'ORA-00028: "your session has been killed"'? 
Well, you obviously don't handle ORA-00028 - Oracle will handle it for you .
Michel Cadot wrote on Tue, 17 July 2012 02:06
There are some errors you want/can handle and the other ones must go on.
Absolutely. And that's why I said exception block needs to fix the cause otherwise code will go into an infinite loop. Now about the fix. There will be same fix for a set of exceptios. For example, there are several exceptions that boil down to "no space in tablespace". Do we want to have multiple WHEN exception clauses with same THEN action versus WHEN OTHERS THEN IF SQLCODE IN (...) THEN add space to tablespace END IF? I say use WHEN OTHERS. In other words, I say if we want to return to statement unconditionally we use WHEN OTHERS, analyze SQLCODE/groups of SQLCODE and provide corrective action. We can even use, in case we can't/don't know how to handle exception but want to return to statement unconditionally, pragma autonomous transaction to log the error so outside world can see it and take corrective action (or kill looping session which is also a corrective action).
Anyway, one thing I absolutely agree - return to statement unconditionally is very "exotic" stuation and must have extremely solid justification.
SY.
|
|
|
|
| Re: Exception Handling [message #560827 is a reply to message #560826] |
Tue, 17 July 2012 05:47   |
 |
Michel Cadot
Messages: 54672 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
Quote:". Do we want to have multiple WHEN exception clauses with same THEN action
You can use "OR" in "WHEN".
Quote:case we can't/don't know how to handle exception but want to return to statement unconditionally, pragma autonomous transaction to log the error so outside world can see it and take corrective action
As I said, logging is the ONLY case WHEN OTHERS could be used.
Regards
Michel
[Updated on: Tue, 17 July 2012 05:48] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
| Re: Exception Handling [message #560864 is a reply to message #560855] |
Tue, 17 July 2012 08:24  |
mnitu
Messages: 136 Registered: February 2008 Location: Reims
|
Senior Member |
|
|
@Solomon:
If you issue just
SQL> lock table emp in exclusive mode;
you'll wait until the other session release lock. After what you can continue with your DDL statement which I supposed will modify your table structure.
[EDITED by LF: removed messy quoting which referred to Solomon's last message. Removed superfluous empty lines]
[Updated on: Tue, 17 July 2012 10:24] by Moderator Report message to a moderator
|
|
|
|