KEMBAR78
Handle the error | PDF
@kamidude
@kamidude
ERRORS
types & debugging
NSError conforms Error

Error is convertible to NSError
*
@kamidude
STOPPING EXECUTION
objc can @catch exceptions / swift cannot
only fatalError is kept on -Ounchecked
*
@kamidude
SWIFT ERRORS
* Every type can adopt Error
basics - conforming
@kamidude
SWIFT ERRORS
Functions Only
Computed Properties
Subscript
basics - throwing errors
*
@kamidude
SWIFT ERRORS
basics - catching errors
catch can match pattern
swift errors are not exceptions !
*
@kamidude
SWIFT ERRORS
common error - ignoring errors
* never ignore errors
@kamidude
SWIFT ERRORS
advanced - rethrowing
non-throwing is a specific 

case of throwing func
*
@kamidude
SWIFT ERRORS
advanced - result equivalency
@kamidude
SWIFT ERRORS
advanced - result equivalency
@kamidude
SWIFT ERRORS
advanced - result equivalency
@kamidude
ERRORS
handling strategies
My own rules of thumb
Adapt to your use case
Expected Unexpected
Domain
• Handle in the application code
• Display details to the user
• Don’t log the error
• Raise an error
• Display details to the user
• Log the error
Technical
• Handle in the application code
• Don’t display details to the user
• Don’t log the error
• Raise an error
• Don’t display details to the user
• Log the error
Domain vs Technical / Expected vs Unexpected
http://www.blueskyline.com/ErrorPatterns/ErrorPatternsPaper.pdf
@kamidude
ERRORS
error semantic - handling strategies
Retry Silently
- Not a solution : if the retry fails, you have to
handle the error eventually
- Exponential backoff
👍 Easy
👎 Not a real solution
My own rules of thumb
Adapt to your use case
@kamidude
ERRORS
error semantic - handling strategies
Ask user to retry / cancel
- Modally or not
- Basic strategy : prevent access to content
👍 Easy
👎 Poor UX
My own rules of thumb
Adapt to your use case
@kamidude
ERRORS
error semantic - handling strategies
Optimistic update
- Show updated local UI
- Works for user actions, not fetching
👍 User friendly / works in most cases
👎 Involves complex synchronization / client logic
My own rules of thumb
Adapt to your use case
@kamidude
ERRORS
error semantic - handling strategies
Crash
- Intended or not
👍 Get info through CrashReporter & fix
👎 Not very user friendly
My own rules of thumb
Adapt to your use case
@kamidude
THANK YOU
questions ?

Handle the error