Fix exception handling in gen engine