Skip to content

Instantly share code, notes, and snippets.

@at-longhoang
Last active March 14, 2016 06:51
Show Gist options
  • Save at-longhoang/ef9526918e9a93c94b7d to your computer and use it in GitHub Desktop.
Save at-longhoang/ef9526918e9a93c94b7d to your computer and use it in GitHub Desktop.
# rescue la noi de xu ly ngoai le.
# raise is phuong thuc giup chung ta dua ra ngoai le. Dua ra ngoai le hien tai. Neu ko co thi bi loi RuntimeError
# retry: lap lai code o begin.
# ensure tuong tu finally
# throw/catch : sau catch la 1 block. tiep tuc xu li khi gap throw thi vang ra ngoai tuong tu nhu break
begin
file = open("file_name.txt")
if file
puts "File opened successfully"
end
rescue
puts "File not found"
retry
end
def raise_and_rescue
begin
puts '1'
raise '2'
puts '3'
rescue
puts '4'
end
puts '5'
end
raise_and_rescue
# Output
1
4
5
catch (:done) do
// some code
throw :done unless #$$%%
//some code
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment