Skip to content

Commit

Permalink
* doc/syntax/control_expressions.rdoc (redo Statement): Added note
Browse files Browse the repository at this point in the history
	  about retry.
	* doc/syntax/exceptions.rdoc:  Added retry statement


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38840 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
drbrain committed Jan 15, 2013
1 parent eaab306 commit d902101
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Wed Jan 16 03:05:50 2013 Eric Hodel <[email protected]>

* doc/syntax/control_expressions.rdoc (redo Statement): Added note
about retry.
* doc/syntax/exceptions.rdoc: Added retry statement

Tue Jan 15 23:12:34 2013 Nobuyoshi Nakada <[email protected]>

* tool/vpath.rb (VPath#list): default separator to PATH_SEPARATOR from
Expand Down
5 changes: 5 additions & 0 deletions doc/syntax/control_expressions.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -397,3 +397,8 @@ Use +redo+ to redo the current iteration:

This prints [0, 1, 3, 3, 5, 5, 7, 7, 9, 9, 11]

In Ruby 1.8 you could also use +retry+ where you used +redo+. This is no
longer true, now you will receive a SyntaxError when you use +retry+ outside
of a +rescue+ block. See {Exceptions}[rdoc-ref:syntax/exceptions.rdoc]
for proper usage of +retry+.

17 changes: 17 additions & 0 deletions doc/syntax/exceptions.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,23 @@ The exception is matched to the rescue section starting at the top, and matches
only once. If an ArgumentError is raised in the begin section it will not be
handled in the StandardError section.

You may retry rescued exceptions:

begin
# ...
rescue
# do something that may change the result of the begin block
retry
end

Execution will resume at the start of the begin block, so be careful not to
create an infinite loop.

Inside a rescue block is the only valid location for +retry+, all other uses
will raise a SyntaxError. If you wish to retry a block iteration use +redo+.
See {Control Expressions}[rdoc-ref:syntax/control_expressions.rdoc] for
details.

To always run some code whether an exception was raised or not, use +ensure+:

begin
Expand Down

0 comments on commit d902101

Please sign in to comment.