add exception handler to codegen