| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> c.d.o.server -> Re: Error handling
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;
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
![]() |
![]() |