Re: Error handling
- From: "fitzjarrell@xxxxxxx" <fitzjarrell@xxxxxxx>
- Date: 15 Sep 2006 07:50:47 -0700
devjnr@xxxxxxxxx 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
.
- References:
- Error handling
- From: devjnr
- Error handling
- Prev by Date: Re: Oracle Benchmark Results for Different Hardware Configurations?
- Next by Date: Re: TAF and FCF together ?
- Previous by thread: Re: Error handling
- Index(es):
Relevant Pages
|