O'Reilly logo

Swift Functional Programming - Second Edition by Dr. Fatih Nayebi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

try!

We can use try! if we know that there is no way a method call will fail, or if it fails then our code will be broken and we should crash the application.

When we use the try! keyword, it disables error propagation and we do not need to have do and catch around our code block because we promise it will never fail! It is a big promise that we should avoid.

In case we have to bypass error handling such as checking whether a database file exists, we can do the following:

let result = try! readFile(path: "path/to") 

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required