Fixing bug with missing try-catch block