Uszanowanko Programowanko #3 - Expect the unexpected - krótka prezentacja o obsłudze wyjątków...
-
Upload
the-software-house -
Category
Technology
-
view
322 -
download
2
Transcript of Uszanowanko Programowanko #3 - Expect the unexpected - krótka prezentacja o obsłudze wyjątków...
What will we talk about?
How does Ruby exception mechanism actually work?
What will we talk about?
How does Ruby exception mechanism actually work?
How can we use it?
What will we talk about?
How does Ruby exception mechanism actually work?
How can we use it?
How should we use it?
In other words
What to throw?
How to throw?
How not to throw
When to throw?And finally…
Ok. Let’s get serious
Ok. Let’s get serious
When we fail?“When a method's preconditions are met, but it is unable to either deliver on its promised postconditions, or to maintain the object invariant, then it is in breach of its contract; it has failed.”
So… here comes exceptions
RAISE
RAISEor fail
Call #exception to get the exception object.
Set the backtrace. (#set_backtrace)
Set the global exception variable ($!)
Throw the exception object up the call stack.
The exception has been thrown. What now?
Rescueto the rescue!
Be careful not to ensure ‘return`
Did you know…
Did you know…that in Ruby…
Did you know…that in Ruby…
we have ‘retry’?!
#shock #niedowierzanie
re-raising
re-raising
STORY TIME!
STORY TIME!
What to do?When dealing with external service/process catch all and log
CircuitBreaker (there’s a gem)
Just exit
Expect only unexpected!
…ask yourself, 'Will this code still run if I remove all the exception handlers?" If the answer is "no", then maybe exceptions are being used in non-exceptional circumstances.
Need to jump up the stack?
Don’t use exceptions
Your answer is -throw… catch
Ok! ok! I am nearly finished!
My errors
Your interest zone
Where to find more?
“Exceptional Ruby” - Avdi Grimm - Base for this short talk
"Object Oriented Software Construction” - Bertrand Meyer