阅读背景:

为什么在一个循环内的事务中不调用next ?

来源:互联网 

I have a loop like this:

我有这样一个循环:

# Iterate a list of items
req_wf_list.each do |req_wf|
    # Begin a transaction
    ReqWf.transaction do # ReqWf is an ActiveRecord model class
        # Do some things
        # ...

        # 1. I want to be able to continue processing with the
        #    next iteration of the loop if there is an error here
        # 2. I also want to rollback the transaction associated with
        #    this particular iteration if I encounter an error
        begin
            # Do something that might return an error
        rescue
            # Do some error processing
            puts "Caught such and such error"

            # Don't complete transaction (rollback),
            # don't "do some more things",
            # proceed to next item in req_wf_list
            next
        end

        # Do some more things
        # Shouldn't make it here if there is an error but I do indeed make it here
        # ...

    # End transaction
    end

# End loop
end
# Iterat



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: