Swift uses throw
, try
, and catch
to handle errors gracefully and keep your app from crashing.
try
and catch
throws
on functions that can throw errors.try?
to convert errors into optional values.try!
only if you’re 100% sure no error will occur (risky!).do-catch
or propagate them.