Top Banner
@kamidude
17

Handle the error

Apr 05, 2017

Download

Software

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Handle the error

@kamidude

Page 2: Handle the error

@kamidude

ERRORStypes & debugging

NSError conforms ErrorError is convertible to NSError

*

Page 3: Handle the error

@kamidude

STOPPING EXECUTION

objc can @catch exceptions / swift cannot only fatalError is kept on -Ounchecked

*

Page 4: Handle the error

@kamidude

SWIFT ERRORS

* Every type can adopt Error

basics - conforming

Page 5: Handle the error

@kamidude

SWIFT ERRORS

Functions Only Computed Properties Subscript

basics - throwing errors

*

Page 6: Handle the error

@kamidude

SWIFT ERRORSbasics - catching errors

catch can match pattern swift errors are not exceptions !

*

Page 7: Handle the error

@kamidude

SWIFT ERRORScommon error - ignoring errors

* never ignore errors

Page 8: Handle the error

@kamidude

SWIFT ERRORSadvanced - rethrowing

non-throwing is a specific case of throwing func

*

Page 9: Handle the error

@kamidude

SWIFT ERRORSadvanced - result equivalency

Page 10: Handle the error

@kamidude

SWIFT ERRORSadvanced - result equivalency

Page 11: Handle the error

@kamidude

SWIFT ERRORSadvanced - result equivalency

Page 12: Handle the error

@kamidude

ERRORShandling 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

Page 13: Handle the error

@kamidude

ERRORSerror 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

Page 14: Handle the error

@kamidude

ERRORSerror 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

Page 15: Handle the error

@kamidude

ERRORSerror 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

Page 16: Handle the error

@kamidude

ERRORSerror 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

Page 17: Handle the error

@kamidude

THANK YOUquestions ?