Need suggestion how can I skip the rest par inside a loop when erro is raised

I need one suggestions from you :-

Suppose I do have a code as below:

until row == nil do
#code1
begin
#code2 <~~ which can raise an error
rescue
end
#here I want some guard which can check,if any error occurred or
not.If #error then skip below part and continue from the next row.
#code3
row+=1
end

Just use error handling properly.

begin
#standard code
rescue
#only runs if an error occurred
else
#only runs if an error did not occur
ensure
#always runs at the end regardless of error level
end

On Sep 12, 2013, at 8:56 AM, Joel P. [email protected] wrote:

end
It seems to me that OP may not even understand:

begin
#standard code
#only runs if no error earlier in this block
rescue
#only runs if an error occurred
end
#always runs as long as all exceptions are caught and none are re-thrown


Scott R.
[email protected]
http://www.elevated-dev.com/
(303) 722-0567 voice

Joel P. wrote in post #1121289:

Just use error handling properly.

begin
#standard code
rescue

I am looking for the below operations,but only when error will be
occured :

a = (1…10)
i=0
until a.size>10
next i+=1 if i<5 # this should be done on Error
p a[i]
i+=1
end

If still I am not clear,please let me know the confusions.

until val == nil
#line1
#line2 #<~~ error can be generated here.If error happened I want to
start
from #line1 again.skipping the below code.
#line3

end

Thanks

Maybe a real example would help, rather than infinite-loop pseudo-code.

val = -3
until val > 2
begin
val +=1
1/val
rescue
puts 'Error on ’ + val.to_s
else
puts 'No Error on ’ + val.to_s
end
puts 'Finished with ’ + val.to_s
end

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs