Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Catch and Throw in Ruby
Search
Aliaksandr Lomau
July 18, 2018
Technology
50
0
Share
Catch and Throw in Ruby
Rubizza Camp Fire, July 2018
Aliaksandr Lomau
July 18, 2018
More Decks by Aliaksandr Lomau
See All by Aliaksandr Lomau
Fails Night
allomov
0
57
"Ya Ne Lochu Comp" Challenge.
allomov
1
100
Mortal Rubizza
allomov
0
100
Рэмбовидная проблема: особенности развития открытых технологий
allomov
0
58
Vault-tec: Safest Future
allomov
0
270
Promises and Reality
allomov
1
61
Cloud Theory for Rubizza Classes
allomov
0
97
Антология деплоя
allomov
0
83
Not For Recording: BOSH User Life Stories
allomov
0
87
Other Decks in Technology
See All in Technology
FessのAI検索モード:検索システムとLLMへの取り組み
marevol
0
180
QAエンジニアはどうやって プロダクト議論の場に入れるのか?
moritamasami
2
330
データ定義の混乱と戦う 〜 管理会計と財務会計 〜
wonohe
0
170
色を視る
yuzneri
0
310
[Scram Fest Niigata2026]Quality as Code〜AIにQAの思考を再現させる試み〜
masamiyajiri
1
180
Digital Independence: Why, When and How
wannesrams
0
260
大学職員のための生成AI最前線 :最前線を、AIガバナンスとして読み直すためのTips
gmoriki
2
3.3k
カオナビに Suspenseを導入するまで / The Road to Suspense at kaonavi
kaonavi
1
160
AI駆動開発で生産性を追いかけたら、行き着いたのは品質とシフトレフトだった
littlehands
0
300
AI와 협업하는 조직으로의 여정
arawn
0
580
フロントエンドの相手が変わった - AIが加わったWebの新しいインターフェース設計
azukiazusa1
31
9.5k
サービスの信頼性を高めるため、形骸化した「プロダクションミーティング」を立て直すまでの取り組み
stefafafan
1
220
Featured
See All Featured
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
10k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.5k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
360
A Tale of Four Properties
chriscoyier
163
24k
Between Models and Reality
mayunak
3
280
The Spectacular Lies of Maps
axbom
PRO
1
720
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
180
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Claude Code のすすめ
schroneko
67
220k
Intergalactic Javascript Robots from Outer Space
tanoku
273
27k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
118
110k
Transcript
None
Alialksandr Lomau VETERANT EL “CAPITAN” DEPLOY https://speakerdeck.com/allomov https://twitter.com/code1n
They can be everywhere!
None
None
None
None
These Pokemons Are ...
None
None
None
None
Variable is not initialized
Variable is not initialized Wrong argument type
Variable is not initialized Wrong argument type File does not
exist
Variable is not initialized Wrong argument type File does not
exist Not enough memory
Variable is not initialized Wrong argument type File does not
exist Not enough memory water pokemon is definitely a memory leak
Ruby == Minefield
Ruby == Minefield
Catche Pokemon with Pokeball
None
== Exception Class
None
rescue SomeError => e # ... end rescue
rescue SomeError, SomeOtherError => e # ... end multiple rescue
rescue SomeError => e # ... rescue SomeOtherError => e
# ... end stacking rescue
rescue rescue # ... end # is equivalent to: rescue
StandardError # ... end
rescue
rescue rescue Exception => e # ... end
rescue rescue => error # ... end # is equivalent
to: rescue StandardError => error # ... end
rescue begin raise "Timeout while reading from socket" rescue errors_with_message(/socket/)
puts "Ignoring socket error" end
rescue def errors_with_message(pattern) m = Module.new m.singleton_class.instance_eval do define_method(:===) do
|e| pattern === e.message end end m end
raise raise(exception_class_or_object, message, backtrace)
raise raise # is equivalent to: raise RuntimeError
raise raise 'An error has occured.' # is equivalent to
: raise RuntimeError, 'An error has occured.'
raise raise RuntimeError, 'An error has occured.' # is equivalent
to : raise RuntimeError.new('An error has occured.')
raise raise RuntimeError, 'An error' # is equivalent to :
raise RuntimeError, 'An error', caller(0)
caller 2.4.2 :005 > puts caller(0).join("\n") (irb):5:in `irb_binding' /Users/allomov/.rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/irb/workspace.rb:87:in `eval'
/Users/allomov/.rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/irb/workspace.rb:87:in `evaluate' /Users/allomov/.rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/irb/context.rb:381:in `evaluate' /Users/allomov/.rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/irb.rb:493:in `block (2 levels) in eval_input' /Users/allomov/.rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/irb.rb:627:in `signal_status' /Users/allomov/.rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/irb.rb:490:in `block in eval_input' /Users/allomov/.rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/irb/ruby-lex.rb:246:in `block (2 levels) in each_top_level_statement' /Users/allomov/.rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/irb/ruby-lex.rb:232:in `loop' /Users/allomov/.rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/irb/ruby-lex.rb:232:in `block in each_top_level_sta /Users/allomov/.rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/irb/ruby-lex.rb:231:in `catch' /Users/allomov/.rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/irb/ruby-lex.rb:231:in `each_top_level_statement' /Users/allomov/.rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/irb.rb:489:in `eval_input' /Users/allomov/.rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/irb.rb:430:in `block in run' /Users/allomov/.rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/irb.rb:429:in `catch' /Users/allomov/.rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/irb.rb:429:in `run' /Users/allomov/.rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/irb.rb:385:in `start' /Users/allomov/.rvm/rubies/ruby-2.4.2/bin/irb:11:in `<main>' => nil
global variable •$! •$ERROR_INFO note: set it to nil to
rescue exception
ensure begin # do something raise 'An error has occured.'
rescue => e puts 'I am rescued.' ensure puts 'This code always is executed.' end
retry tries = 0 begin tries += 1 puts "Trying
#{tries}..." raise "Didn't work" rescue retry if tries < 3 puts "I give up" end
else begin yield rescue puts "Only on error" else puts
"Only on success" ensure puts "Always executed" end
• Use exception when you need • Wrap exception when
re-raising • Avoid raising during ensure • Exception is your method interface too • Classify your exceptions • Readable exceptional code • Declare classes for app exception good points
Benchmarks
Circuit Breaker pattern
Anti-Patterns • Exceptions controlled flow • rescue nil
What to do with errors? • handle them • send
emails with them • send them to error report system • errbit • pappertrail • elk • … etc.
Alternatives • Callbacks on fails (JavaScript) • Promises (JavaScript) •
Returning codes (golang)
None
None
None
To Know More
throw "End"