Avoid NPE error in try-catch