Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2009
    Location
    Mumbai
    Posts
    29

    Unanswered: Exception handling continue loop with out break

    Hi,

    I have written a procedure, in which i have cursor, looping through the cursor,
    i want to handle exception in this loop such way that it should continue with the next iteration not to break out the loop.

  2. #2
    Join Date
    Mar 2010
    Location
    Vienna, Austria
    Posts
    149
    That's how to do it (in this example, a divide by zero - exception is caught):

    Code:
    begin
      for i in 1..10 loop
        begin
           dbms_output.put_line('i | i / (i - 5):' || i || '|' || i / (i - 5));
        exception
           when ZERO_DIVIDE then dbms_output.put_line ('This Line from exception handler') ;continue;
           when others      then dbms_output.put_line('Error: ' || SQLCODE || ' ' || SQLERRM); exit;
        end;
      end loop;
    end;
    /

    Output:
    Code:
    i | i / (i - 5):1|-,25
    i | i / (i - 5):2|-,6666666666666666666666666666666666666667
    i | i / (i - 5):3|-1,5
    i | i / (i - 5):4|-4
    This Line from exception handler
    i | i / (i - 5):6|6
    i | i / (i - 5):7|3,5
    i | i / (i - 5):8|2,66666666666666666666666666666666666667
    i | i / (i - 5):9|2,25
    i | i / (i - 5):10|2
    Last edited by magicwand; 08-26-10 at 06:57. Reason: typo fixed
    "There is always an easy solution to every problem - neat, plausible, and wrong."
    -- H.L. Mencken

  3. #3
    Join Date
    Jul 2009
    Location
    Mumbai
    Posts
    29
    i am using 10g continue statement is giving error.
    "PLS-00201: identifier 'CONTINUE' must be declared"
    My code goes like this

    Code:
    begin
    <expressions>
    exception
    when others  then 
    dbms_output.put_line('Error: ' || SQLCODE); 
    continue;
    END;

  4. #4
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    >i am using 10g continue statement is giving error.

    Please post URL to documentation for said "CONTINUE" statement.
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  5. #5
    Join Date
    Mar 2010
    Location
    Vienna, Austria
    Posts
    149
    scharan07,

    you can simply omit the CONTINUE in 10g (in 11g CONTINUE just starts the next loop of the iteration).

    The important thing is, to handle the exception in a block within the loop.

    anacedent,

    CONTINUE Statement
    Last edited by magicwand; 08-27-10 at 18:56.
    "There is always an easy solution to every problem - neat, plausible, and wrong."
    -- H.L. Mencken

  6. #6
    Join Date
    Jul 2009
    Location
    Mumbai
    Posts
    29

    Cool

    So it is newly introduced in 11g.
    In 10g it auto do's with out continue statement.

    Thanks for you replies magicwand

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •