Added a try catch block around the generator