This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # TODO: write blog posts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'timeout' | |
| begin | |
| Timeout.timeout(1) do | |
| # spending time doing, say, an IO operation accross the network | |
| sleep 2 | |
| end | |
| rescue | |
| puts "Getting the big file took too long. Try again later." | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class SpecialError < StandardError; end | |
| begin | |
| raise StandardError | |
| rescue | |
| "rescued" | |
| end | |
| # "rescued" | |
| begin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'timeout' | |
| def process_foos(error_to_rescue) | |
| begin | |
| # -> process Foos | |
| # -> if we run out of Foos, raise | |
| sleep 2 | |
| rescue error_to_rescue | |
| # -> email the manager that we ran out of Foos | |
| puts <<-MESSAGE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def subject(throws, catches) | |
| $inner_succeeded=nil | |
| $raised_in_inner=nil | |
| $caught_in_inner=nil | |
| $raised_in_outer=nil | |
| $not_raised_in_outer=nil | |
| begin | |
| Timeout.timeout(0.1, throws){ | |
| begin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| self.class._create_callbacks.select { |callback| callback.kind.eql?(:after) }.collect(&:filter) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def generate_continue_object(*args) | |
| args.each{|a| puts a.inspect} | |
| yield if block_given? | |
| continue_object = Object.new | |
| def continue_object.next_block | |
| if block_given? | |
| yield |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| t = Thread.start{ | |
| begin | |
| puts "starting executing code!" | |
| sleep 1 | |
| puts "done executing code!" # we don't expect to reach here | |
| rescue Exception | |
| puts "rescuing!" # we don't expect to reach here | |
| ensure | |
| puts "ensuring!" # will we reach here????? (yes) | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'thread' | |
| t = Thread.new{ | |
| sleep 0.1 | |
| sleep 0.1 | |
| sleep 0.1 | |
| sleep 0.1 | |
| sleep 0.1 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def do_jobs | |
| begin | |
| while true | |
| # do interesting things | |
| end | |
| rescue NoMoreDiskSpace | |
| # tidy things up | |
| end | |
| end |