17
@kamidude

Handle the error

Embed Size (px)

Citation preview

@kamidude

@kamidude

ERRORStypes & debugging

NSError conforms ErrorError 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 ERRORSbasics - catching errors

catch can match pattern swift errors are not exceptions !

*

@kamidude

SWIFT ERRORScommon error - ignoring errors

* never ignore errors

@kamidude

SWIFT ERRORSadvanced - rethrowing

non-throwing is a specific case of throwing func

*

@kamidude

SWIFT ERRORSadvanced - result equivalency

@kamidude

SWIFT ERRORSadvanced - result equivalency

@kamidude

SWIFT ERRORSadvanced - result equivalency

@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

@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

@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

@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

@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

@kamidude

THANK YOUquestions ?