Swift 60秒45 - Running throwing functions

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Swift 60秒45 - Running throwing functions相关的知识,希望对你有一定的参考价值。


0x00 Lesson

Swift ​​doesnt​​ like errors to happen when your program runs, which means it won’t let you run an error-throwing function by accident.

Instead, you need to call these functions using three new keywords: ​​do​​​ starts a section of code that might cause problems, ​​try​​​ is used before every function that might throw an error, and ​​catch​​ lets you handle errors gracefully.

If any errors are thrown inside the ​​do​​​ block, execution immediately jumps to the ​​catch​​​ block. Let’s try calling ​​checkPassword()​​ with a parameter that throws an error:

do 
try checkPassword("password")
print("That password is good!")
catch
print("You cant use that password.")

When that code runs, ​​"You cant use that password"​​​ is printed, but “That password is good” won’t be - that code will never be reached. because the ​​error​​ is thrown.


0x01 我的小作品

欢迎体验我的作品之一:​​小五笔​​​ 五笔学习好帮手
​App Store​​ 搜索即可~



以上是关于Swift 60秒45 - Running throwing functions的主要内容,如果未能解决你的问题,请参考以下文章

Swift 60秒42 - Default parameters

pyqt小计

度分秒换算的方法是啥?

度分秒的换算方法是啥?

度数如何化成分秒,求过程。

有没有办法让 EC2 实例中的请求保持超过 60 秒?