NumberFormatException is apparently the answer, so now this question will not show up as unanswered.
try{
int port=Integer.parseInt(JOptionPane.showInputDialog("Please insert the default port!");
}catch(NumberFormatException e){
//handle error
}