Home » SQL & PL/SQL » SQL & PL/SQL » Exception control flow
Exception control flow [message #270385] Wed, 26 September 2007 14:00 Go to next message
apollo
Messages: 20
Registered: September 2007
Junior Member
if I have code that looks like this...
DECLARE
  my_exception EXCEPTION;
BEGIN
  FOR index IN 1..100 LOOP
    IF index = 5 THEN
      RAISE my_exception;
    END IF;
  END LOOP;
EXCEPTION
  WHEN my_exception THEN
    NULL;
END;

...what happens after the exception is raised? will the procedure stop executing completely? or will the FOR loop continue to the next value?
thanks
Re: Exception control flow [message #270388 is a reply to message #270385] Wed, 26 September 2007 14:03 Go to previous messageGo to next message
BlackSwan
Messages: 25035
Registered: January 2009
Location: SoCal
Senior Member
>...what happens after the exception is raised? will the procedure stop executing completely? or will the FOR loop continue to the next value?


please run YOUR code & answer YOUR own questions.
Re: Exception control flow [message #270406 is a reply to message #270388] Wed, 26 September 2007 15:32 Go to previous messageGo to next message
Littlefoot
Messages: 20891
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
The way you've written it, exception would stop this PL/SQL procedure's execution (as well as the FOR loop's next value).

However, if you rewrite it as
DECLARE
  my_exception EXCEPTION;
BEGIN
  FOR index IN 1..100 LOOP
    BEGIN
      IF index = 5 THEN
         RAISE my_exception;
      END IF;
    EXCEPTION
      WHEN my_exception THEN
        NULL;
    END;
  END LOOP;
END;
(include additional BEGIN - EXCEPTION - END block within the FOR loop), an exception would be raised, handled, but FOR loop would continue to ... hm, loop.
Re: Exception control flow [message #270407 is a reply to message #270406] Wed, 26 September 2007 15:38 Go to previous message
apollo
Messages: 20
Registered: September 2007
Junior Member
gotcha. thanks!
Previous Topic: Online books
Next Topic: Eliminating the duplicate records
Goto Forum:
  


Current Time: Sat Dec 03 16:28:03 CST 2016

Total time taken to generate the page: 0.08870 seconds