codice:

int i;
try{
    i = Integer.parseInt(stringa);
}
catch(Exception e){
    System.out.println("Eccezione " + e);
}