combine two try-catch block into one, make it cleaner.