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
0
34
Catch and Throw in Ruby
Rubizza Camp Fire, July 2018
Aliaksandr Lomau
July 18, 2018
Tweet
Share
More Decks by Aliaksandr Lomau
See All by Aliaksandr Lomau
Fails Night
allomov
0
31
"Ya Ne Lochu Comp" Challenge.
allomov
1
78
Mortal Rubizza
allomov
0
64
Рэмбовидная проблема: особенности развития открытых технологий
allomov
0
42
Vault-tec: Safest Future
allomov
0
180
Promises and Reality
allomov
1
48
Cloud Theory for Rubizza Classes
allomov
0
75
Антология деплоя
allomov
0
70
Not For Recording: BOSH User Life Stories
allomov
0
69
Other Decks in Technology
See All in Technology
多数のWebサービスをECS/Fargate構成で効率よく構築・運用するなら copilot-cli
interu
2
170
塩野義製薬様のAWS統合管理戦略:Organizations設計と運用の具体例
tkikuchi
0
320
今日から始める技術的負債の解消
leveragestech
3
460
エンジニア向け会社紹介資料
caddi_eng
14
270k
v-modelの歩みを振り返る
bengo4com
5
2.4k
暴カワでビデオシンセサイザーを導入する技術
yuchi
2
130
なぜ Rack を理解すべきかプレトーク / Why should you understand Rack - Pre-talk
hogelog
0
230
Reality is not an End-to-End Prediction Problem: Applied NLP in the Age of Generative AI
inesmontani
PRO
0
190
とある事業会社にとっての Kaggler の魅力
hakubishin3
7
1.6k
Snowflakeでスロークエリ改善に取り組んだ話
tabata0208
0
130
人工衛星開発のための C2A フレームワークとその開発体験
sksat
0
110
不要なリソースを自動で定期的に整理する方法 ~Sandboxアカウントのコストを削減しよう!~
amixedcolor
4
240
Featured
See All Featured
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
9
630
10 Git Anti Patterns You Should be Aware of
lemiorhan
653
59k
Producing Creativity
orderedlist
PRO
341
39k
Testing 201, or: Great Expectations
jmmastey
38
7k
YesSQL, Process and Tooling at Scale
rocio
167
14k
Code Reviewing Like a Champion
maltzj
519
39k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Art, The Web, and Tiny UX
lynnandtonic
296
20k
Building Better People: How to give real-time feedback that sticks.
wjessup
363
19k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
13
1.8k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
225
22k
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"