Simple try/catch array error
              in 
             Programming Questions 
              •  
              1 year ago    
            
 
           
             So I am splitting data that comes in from a serial port and saving each piece as a separate part of the array. Later in the code I reference parts of the array that I saved. The array's length is either 1 or 12. When the length is 1 I can't reference the array for my display leading to errors, so I am trying to set it to catch the errors and force that part of the array to exist.
            
            
Below is the code I am trying to use and I keep getting unexpected '{' as an error....
            
            
 
            
           Below is the code I am trying to use and I keep getting unexpected '{' as an error....
-  try {
text(Authourize[int(dataTypes[3])], 135, 50, 80, 25);//textboxes and choose the correct auth code
}
catch(ArrayIndexOutOfBoundsException e) {//catches if most sent but 3= number not in array
dataTypes={"0","0","0","0"};
}
catch(NullPointerException e) {//catches if not enough sent ie 3 DNE
dataTypes={"0","0","0","0"};
} 
             I tried to do  the same thing with an if statement which is less preferable because then the program checks dataTypes on every loop, but I still get the same error...
             
             
             
 
           -   if (dataTypes.length<3) {
dataTypes= {"0", "0", "0", "0"};
}
else if (int(dataTypes[3])>49) {
dataTypes[3]="0";
} 
              I know this is probably a really silly question but any help would be greatly appreciated.
              
              
Thanks in advance-
Adie
             
            Thanks in advance-
Adie
 
              
              1  
            
 
            