Board index » delphi » handle more than one handle exception individually in procedure

handle more than one handle exception individually in procedure

I wish to handle more than one handle exception individually in procedure,
if there's suggestion
I use the
"When any do" cause
inside checking "GDSCODE = 'arith_except'"
<bra><bra>
The engine reject me.

Any help, thank you.

 

Re:handle more than one handle exception individually in procedure


Quote
> I wish to handle more than one handle exception individually in procedure,
> if there's suggestion
> I use the
> "When any do" cause
> inside checking "GDSCODE = 'arith_except'"

BEGIN
  ...
  WHEN GDSCODE arith_except DO EXIT;
  WHEN GDSCODE convert_error DO EXIT;
  WHEN SQLCODE -803 DO EXIT;
  WHEN SQLCODE -817 DO EXIT;
  WHEN EXCEPTION MyException DO EXIT;
END

--
Ivan
http://www.volny.cz/iprenosil/interbase

Re:handle more than one handle exception individually in procedure


Initially that approach tried.  Now this time having heard what you say I
re-try again with following:

----------------------------------------------------------------------------
-------\
set term!;
ALTER PROCEDURE TESTEXCEPTION
(
  TEXT VARCHAR(80) CHARACTER SET ASCII
)
RETURNS
(
  A VARCHAR(9) CHARACTER SET ASCII
)
AS
 begin
  insert into noiseworddefinitions(definednoiseword) values (:text);
  a = :text;
  suspend;
  when GDSCODE unique_key_violation do
  begin
   insert into noiseworddefinitions(definednoiseword) values
(substr(:text,1,15));
   a = "unique_";
   suspend;
  end
  when GDSCODE arith_except do
  begin
   insert into noiseworddefinitions(definednoiseword) values
(substr(:text,1,15));
   a = "arith_";
   suspend;
  end
end!
set term;!
commit;
----------------------------------------------------------------------------
--------------
First time, input:
   "select * from
testException("ssafafafafafafsjfofjowofejewojwojfwwojjwjfojwofjoeowejfe");"
   OUTPUT:  "arith_"
Second tim, input:
   "commit"(for previous command)
   "select * from
testException("ssafafafafafafsjfofjowofejewojwojfwwojjwjfojwofjoeowejfe");"
   OUTPUT:  Error message for "unique key violation" on the table
   EXPECTED OUTPUT SHOULD BE:  "unique_"
----------------------------------------------------------------------------
---------------
Conclusion:
Semantically work as Console don't "boot" me, but just not WORK.......
----------------------------------------------------------------------------
--------------

If any other suggestion, thank you first.

Quote
"Ivan Prenosil" <preno...@ms.anet.cz> wrote in message

news:3df727f5@newsgroups.borland.com...
Quote
> > I wish to handle more than one handle exception individually in
procedure,
> > if there's suggestion
> > I use the
> > "When any do" cause
> > inside checking "GDSCODE = 'arith_except'"

> BEGIN
>   ...
>   WHEN GDSCODE arith_except DO EXIT;
>   WHEN GDSCODE convert_error DO EXIT;
>   WHEN SQLCODE -803 DO EXIT;
>   WHEN SQLCODE -817 DO EXIT;
>   WHEN EXCEPTION MyException DO EXIT;
> END

> --
> Ivan
> http://www.volny.cz/iprenosil/interbase

Re:handle more than one handle exception individually in procedure


Quote
> ALTER PROCEDURE TESTEXCEPTION
> (
>   TEXT VARCHAR(80) CHARACTER SET ASCII
> )
> RETURNS
> (
>   A VARCHAR(9) CHARACTER SET ASCII
> )
> AS
>  begin
>   insert into noiseworddefinitions(definednoiseword) values (:text);
>   a = :text;
>   suspend;
>   when GDSCODE unique_key_violation do
>   begin
>    insert into noiseworddefinitions(definednoiseword) values
> (substr(:text,1,15));
>    a = "unique_";
>    suspend;
>   end
>   when GDSCODE arith_except do
>   begin
>    insert into noiseworddefinitions(definednoiseword) values
> (substr(:text,1,15));
>    a = "arith_";
>    suspend;
>   end
> end!
> set term;!
> commit;
> ----------------------------------------------------------------------------
> --------------
> First time, input:
>    "select * from
> testException("ssafafafafafafsjfofjowofejewojwojfwwojjwjfojwofjoeowejfe");"
>    OUTPUT:  "arith_"
> Second tim, input:
>    "commit"(for previous command)
>    "select * from
> testException("ssafafafafafafsjfofjowofejewojwojfwwojjwjfojwofjoeowejfe");"
>    OUTPUT:  Error message for "unique key violation" on the table
>    EXPECTED OUTPUT SHOULD BE:  "unique_"

First time is executed:
1)   insert into noiseworddefinitions(definednoiseword) values ('ssafafafafafafsjfofjowofejewojwojfwwojjwjfojwofjoeowejfe');
2)   a = :text;       <- because "a" is only VARCHAR(9), exception is raised, and handled by
3)   when GDSCODE arith_except do
and thus "ssafafafafafafs" is inserted into table.

Second time you do the same, but the value "ssafafafafafafs" is already present in table ...
Seems o.k.  (at least, you get what you ask for :-)

--
Ivan
http://www.volny.cz/iprenosil/interbase

Re:handle more than one handle exception individually in procedure


NO No ...what i want it is catching both exception not thrown me and
interrupt the application who is calling the procedure.....
if the second return is "unique_" then it indicate it is catch and
applicatoin won't be interrupted, now it thrown SQL unique_key_violation and
interrupting the application.  That's not what I want and it definitely not
performing as what I wish.

Thank you first, any more clue for me?

"Ivan Prenosil" <preno...@ms.anet.cz> ???g??ls?D
:3df73...@newsgroups.borland.com...

Quote
> > ALTER PROCEDURE TESTEXCEPTION
> > (
> >   TEXT VARCHAR(80) CHARACTER SET ASCII
> > )
> > RETURNS
> > (
> >   A VARCHAR(9) CHARACTER SET ASCII
> > )
> > AS
> >  begin
> >   insert into noiseworddefinitions(definednoiseword) values (:text);
> >   a = :text;
> >   suspend;
> >   when GDSCODE unique_key_violation do
> >   begin
> >    insert into noiseworddefinitions(definednoiseword) values
> > (substr(:text,1,15));
> >    a = "unique_";
> >    suspend;
> >   end
> >   when GDSCODE arith_except do
> >   begin
> >    insert into noiseworddefinitions(definednoiseword) values
> > (substr(:text,1,15));
> >    a = "arith_";
> >    suspend;
> >   end
> > end!
> > set term;!
> > commit;

> --------------------------------------------------------------------------
--
> > --------------
> > First time, input:
> >    "select * from

testException("ssafafafafafafsjfofjowofejewojwojfwwojjwjfojwofjoeowejfe");"
Quote
> >    OUTPUT:  "arith_"
> > Second tim, input:
> >    "commit"(for previous command)
> >    "select * from

testException("ssafafafafafafsjfofjowofejewojwojfwwojjwjfojwofjoeowejfe");"
Quote
> >    OUTPUT:  Error message for "unique key violation" on the table
> >    EXPECTED OUTPUT SHOULD BE:  "unique_"

> First time is executed:
> 1)   insert into noiseworddefinitions(definednoiseword) values

('ssafafafafafafsjfofjowofejewojwojfwwojjwjfojwofjoeowejfe');
Quote
> 2)   a = :text;       <- because "a" is only VARCHAR(9), exception is

raised, and handled by
Quote
> 3)   when GDSCODE arith_except do
> and thus "ssafafafafafafs" is inserted into table.

> Second time you do the same, but the value "ssafafafafafafs" is already

present in table ...

- Show quoted text -

Quote
> Seems o.k.  (at least, you get what you ask for :-)

> --
> Ivan
> http://www.volny.cz/iprenosil/interbase

Other Threads