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
32
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
26
"Ya Ne Lochu Comp" Challenge.
allomov
1
72
Mortal Rubizza
allomov
0
59
Рэмбовидная проблема: особенности развития открытых технологий
allomov
0
35
Vault-tec: Safest Future
allomov
0
140
Promises and Reality
allomov
1
44
Cloud Theory for Rubizza Classes
allomov
0
71
Антология деплоя
allomov
0
66
Not For Recording: BOSH User Life Stories
allomov
0
64
Other Decks in Technology
See All in Technology
IaCジェネレーターとBedrockで詳細設計書を生成してみた
tsukasa_ishimaru
4
860
Python と Snowflake はズッ友だょ!~ Snowflake の Python 関連機能をふりかえる ~
__allllllllez__
2
140
「スニダン」開発組織の構造に込めた意図 ~組織作りはパッションや政治ではない!~
rinchsan
4
600
エンジニア候補者向け資料2024.04.24.pdf
macloud
0
3.3k
FrontDoorとWebAppsを組み合わせた際のリダイレクト処理の注意点
kenichirokimura
1
700
ルーターでプレゼンする
puhitaku
1
3.2k
EM完全に理解した と思ったけど、 やっぱり何も分からなかった話 / EM Night Fukuoka #1
hirutas
0
200
Microsoft for Startups Founders Hub_20240429 update
daikikanemitsu
1
2.4k
Microsoft Intune 勉強会 第 2 回目
tamaiyutaro
2
360
Babylon.js JAPAN活動紹介 (2024/4)
limes2018
1
100
ExaDB-D dbaascli で出来ること
oracle4engineer
PRO
0
2.1k
TechFeed Experts Night#27 〜 フロントエンドフレームワーク最前線 (Svelte)
baseballyama
2
590
Featured
See All Featured
Scaling GitHub
holman
457
140k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
22
1.6k
Become a Pro
speakerdeck
PRO
12
4.6k
Music & Morning Musume
bryan
41
5.6k
Automating Front-end Workflow
addyosmani
1357
200k
Designing Experiences People Love
moore
136
23k
Mobile First: as difficult as doing things right
swwweet
217
8.6k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
18
1.6k
Stop Working from a Prison Cell
hatefulcrawdad
267
19k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
245
20k
Gamification - CAS2011
davidbonilla
76
4.6k
Designing with Data
zakiwarfel
96
4.8k
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"