Added try-catch around the functionality, which throws an error when the inner functionality failed.