Error "variable numAlum might not have been initialized"

-1

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

    
asked by Eduardo Neira Flores 28.05.2018 в 00:46
source

1 answer

0

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
    
answered by 28.05.2018 в 18:19