v.s. ‘your token is invalid’ • Can be used to block unnecessary further more operations • Forced A developer can ignore (or not be aware of) your return status and go on blissfully unaware that something failed. Exception can't be silently ignored.
`raise` (RuntimeError) • Raise with specified type of exception e.g. `raise App::AuthenticationFailedError, ‘token is invalid’` Note: Remember to define your own errors
`rescue` (StandardError, almost all usual exceptions) • Rescue specified type of exception • Rescue a exception • Rescue multiple exceptions parallelism • Use `retry` and `ensure`
the former will raise error if transition failed, so we can handle AEAP • Communication between different layers(M v.s. C) If you need to display error messages to users, you should use flash, but flash is existed at controller layer.
body of a method definition is an implicit begin-end block • Be careful to rescue `Exception` • A library should have one subclass of StandardError or RuntimeError and have specific exception types inherit from it
Ruby's exception hierarchy, so when you rescue Exception you rescue from everything • Exceptions to events map: • Interrupt => Ctrl + C • SignalException => kill -9 • SyntaxError