Reorder code generation so it still works if an exception is thrown.