int a = 0;
try{
a = Integer.parseInt(s);
}
catch(NumberFormatException e){
//codice da seguire se scatta l'eccezione
}