曾与蒿藜同雨露,한때 잡초와 쑥과 함께 비와 이슬을 나누던 곳이 이제는 소나무와 삼나무와 함께 서리와 눈을 견뎌내고 있다.终随松柏到冰霜.かつては雑草やヨモギと共に雨や露を分かち合っていたが、今では松やヒノキと共に霜や雪に耐えている。曾与蒿藜同雨露,Once sharing rain and dew with weeds and wormwood, now enduring frost and snow with pines and cypresses.终随松柏到冰霜.曾与蒿藜同雨露한때 잡초와 쑥과 함께 비와 이슬을 나누던 곳이 이제는 소나무와 삼나무와 함께 서리와 눈을 견뎌내고 있다.,终随松柏到冰霜.譖セ荳手珍阯懷酔髮ィ髴イ�檎サ磯囂譚セ譟丞芦蜀ー髴�曾与蒿藜同雨露,鏇句笌钂胯棞鍚岄洦闇诧紝缁堥殢鏉炬煆鍒板啺闇�终随松柏到冰霜.曾与蒿藜同雨露,한때 잡초와 쑥과 함께 비와 이슬을 나누던 곳이 이제는 소나무와 삼나무와 함께 서리와 눈을 견뎌내고 있다.终随松柏到冰霜.曾与蒿藜同雨露,终随松柏到冰霜.
U:RDoc::TopLevel[ i I"syntax/exceptions.rdoc:EFcRDoc::Parser::Simpleo:RDoc::Markup::Document:@parts[(S:RDoc::Markup::Heading:
leveli: textI"Exception Handling;To:RDoc::Markup::BlankLine o:RDoc::Markup::Paragraph;[I"5Exceptions are rescued in a +begin+/+end+ block:;T@
o:RDoc::Markup::Verbatim;[
I"begin
;TI" # code that might raise
;TI"rescue
;TI" # handle exception
;TI" end
;T:@format0o;
;[I"TIf you are inside a method, you do not need to use +begin+ or +end+ unless you ;TI"3wish to limit the scope of rescued exceptions:;T@
o;;[
I"def my_method
;TI"
# ...
;TI"rescue
;TI"
# ...
;TI" end
;T;0o;
;[I";The same is true for a +class+, +module+, and +block+:;T@
o;;[I"[0, 1, 2].map do |i|
;TI" 10 / i
;TI"rescue ZeroDivisionError
;TI" nil
;TI" end
;TI"#=> [nil, 10, 5]
;T;0o;
;[I"FYou can assign the exception to a local variable by using <tt>=> ;TI"8variable_name</tt> at the end of the +rescue+ line:;T@
o;;[I"begin
;TI"
# ...
;TI"rescue => exception
;TI" warn exception.message
;TI". raise # re-raise the current exception
;TI" end
;T;0o;
;[I"QBy default, StandardError and its subclasses are rescued. You can rescue a ;TI"Tspecific set of exception classes (and their subclasses) by listing them after ;TI"+rescue+:;T@
o;;[
I"begin
;TI"
# ...
;TI"%rescue ArgumentError, NameError
;TI"+ # handle ArgumentError or NameError
;TI" end
;T;0o;
;[I"DYou may rescue different types of exceptions in different ways:;T@
o;;[I"begin
;TI"
# ...
;TI"rescue ArgumentError
;TI" # handle ArgumentError
;TI"rescue NameError
;TI" # handle NameError
;TI"rescue
;TI"" # handle any StandardError
;TI" end
;T;0o;
;[I"UThe exception is matched to the rescue section starting at the top, and matches ;TI"Tonly once. If an ArgumentError is raised in the begin section, it will not be ;TI"*handled in the StandardError section.;T@
o;
;[I"&You may retry rescued exceptions:;T@
o;;[I"begin
;TI"
# ...
;TI"rescue
;TI"D # do something that may change the result of the begin block
;TI"
retry
;TI" end
;T;0o;
;[I"QExecution will resume at the start of the begin block, so be careful not to ;TI"create an infinite loop.;T@
o;
;[ I"RInside a rescue block is the only valid location for +retry+, all other uses ;TI"Swill raise a SyntaxError. If you wish to retry a block iteration use +redo+. ;TI"MSee {Control Expressions}[rdoc-ref:syntax/control_expressions.rdoc] for ;TI"
details.;T@
o;
;[I"RTo always run some code whether an exception was raised or not, use +ensure+:;T@
o;;[I"begin
;TI"
# ...
;TI"rescue
;TI"
# ...
;TI"ensure
;TI" # this always runs
;TI" end
;T;0o;
;[I"@You may also run some code when an exception is not raised:;T@
o;;[I"begin
;TI"
# ...
;TI"rescue
;TI"
# ...
;TI"
else
;TI"5 # this runs only when no exception was raised
;TI"ensure
;TI"
# ...
;TI"end;T;0:
@file@:0@omit_headings_from_table_of_contents_below0