Fix error handling in try/catch