Re: Error handling




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

.



Relevant Pages

  • Re: long double versions of functions in gcc under Cygwin
    ... rather than the nearest enclosing one) and a decent exception ... them it doesn't seem like goto usage would be affected ... int typfun() ... Why use a for loop when it is just a while loop in disguise? ...
    (comp.lang.c)
  • Re: CInternetSession
    ... the presence of the Sleepindicates the serious design flaw. ... Sleep() calls around like pixie dust, your design is fundamentally broken and will need to ... If you use Sleepin a loop, your design is probably wrong and needs to be ... The "First Chance Exception" message usually indicates nothing harmful. ...
    (microsoft.public.vc.mfc)
  • Re: Get_Line problem (GNAT bug?)
    ... Now, if the program specs says: "read the lines from input until EOF", then this for me immediately translates into a loop with some exit condition. ... "Read until" - you have a regular end-of-sequence condition here. ... I'm not convinced that exception might be a correct design choice for breaking the loop that reads data from well formatted file. ...
    (comp.lang.ada)
  • Re: Error handling
    ... with the loop after handle the exception: ... excTest exception; ... lvIdx pls_integer; ...
    (comp.databases.oracle.server)
  • Re: long double versions of functions in gcc under Cygwin
    ... missing feature in the language. ... named break (which could be used to break out of a specified loop ... rather than the nearest enclosing one) and a decent exception ... goto just operates on the control flow of your program. ...
    (comp.lang.c)