Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Error handling

Re: Error handling

From: <fitzjarrell_at_cox.net>
Date: 15 Sep 2006 07:50:47 -0700
Message-ID: <1158331847.866580.272380@m73g2000cwd.googlegroups.com>

devjnr_at_gmail.com wrote:
> I'm trying to handle exception inside a loop, but I should continue
> with the loop after handle the exception:
>
>
> ------------------------------------------------
> declare
> excTest exception;
> lvIdx pls_integer;
> begin
>
> lvIdx := 5;
>
> while (lvIdx < 10)
> loop
>
> dbms_output.put_line(lvIdx);
> raise excTest;
> lvIdx := lvIdx + 1;
>
> end loop;
>
> exception
>
> when excTest then
>
> begin
> dbms_output.put_line('1) exception');
> end;
>
> when others then
>
> begin
> dbms_output.put_line('2) unhandled exception');
> end;
>
> end;
> ------------------------------------------------
>
>
> The problem is that I would loop until "lvIdx" is < 10....
>
> I think it should be possible....or not?
>
> Thx.

Not the way you have it written, as you'll never increment the counter and the loop will run until the output buffer overflows. Do this instead:

SQL> l
  1 declare

  2         excTest    exception;
  3         lvIdx      pls_integer;
  4  begin
  5       lvIdx        := 5;
  6       while (lvIdx < 10)
  7       loop
  8        begin
  9         dbms_output.put_line(lvIdx);
 10         lvIdx := lvIdx + 1;
 11         raise excTest;
 12        exception
 13                when excTest then
 14                          dbms_output.put_line('1) exception');
 15                when others then
 16                          dbms_output.put_line('2) unhandled
exception');
 17        end;
 18       end loop;

 19* end;
SQL> /
5
1) exception
6
1) exception
7
1) exception
8
1) exception
9
1) exception

PL/SQL procedure successfully completed.

SQL> Notice the counter increment is before the raise, not after. This should work as you expect it to.

David Fitzjarrell Received on Fri Sep 15 2006 - 09:50:47 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US