Replaced the try-catch block with a null reference check