I was asked to do this task but when trying to protect with a try catch a variable that deals with an object marks me an error and I would like to see if there is a way to apply the try catch since it is a requirement of the task that try try catch
The solution is to declare the varianle numAlum
outside the block try-catch
, and initialize the variable in 0
.
For example:
...variables
int numAlumno = 0;
...Variables
try{
numAlumno = // aca pones la logica del numero
}catch (Excepcion ex){
//codigo de la exepcion
}finally { //codigo finally }
Alunmos [numAlumno];
//Mas código