Java tutorial
//package com.java2s; //License from project: Apache License public class Main { /** * Convert integer wraped in string to int safely. */ public static int toIntSafely(String text) { int result = -1; text = text.trim(); try { result = Integer.parseInt(text); } catch (NumberFormatException e) { e.printStackTrace(); } return result; } }