cancel
Showing results for 
Search instead for 
Did you mean: 

possible problem handling exceptions

Former Member
2,161

Hi. I use this code to test if a variable exists or not (in this case gnVar)

ALTER TRIGGER  
  ......  
   declare a tinyint;  
   ......  
   begin  
     set gnVar=1;  
     set a=1;  
   exception  
     when others then  
        set a=2;  
   end;  
   if a=1 then  
      --gnVar exists  
   else  
      --gnVar doesn't exist  
   end if;  
   ........  
end  

Is it possible for a to be 1 even if gnVar does not exist (this is the only explanation for some strange data sets)? The code is designed for Sql Anywhere 7 and 9. The problem appeared in Sql Anywhere 9.

Gabriel

Accepted Solutions (0)

Answers (1)

Answers (1)

Breck_Carter
Participant

The following code works as expected in 7.0.3.2046 and 9.0.2.3951 (the V9 test is shown), so you should look elsewhere for an explanation.

FYI if it actually is a bug in V9, it's not going to get fixed, so version-specific branching to call VAREXISTS() may be the only workaround (VAREXISTS was introduced in 8.0.2).

SELECT @@VERSION;
@@VERSION
'9.0.2.3951'

BEGIN
   declare a tinyint;  
   begin  
     set gnVar=1;  
     set a=1;  
   exception  
     when others then  
        set a=2;  
   end;  
   SELECT a;
end

a
2

CREATE VARIABLE gnVar INTEGER;
BEGIN
   declare a tinyint;  
   begin  
     set gnVar=1;  
     set a=1;  
   exception  
     when others then  
        set a=2;  
   end;  
   SELECT a;
end

a
1
Former Member
0 Kudos

Thanks for your answer. I've tested a lot this code, but I don't have other explanation for my problem.