[swift-evolution] Throws? and throws!
Jose Cheyo Jimenez
cheyo at masters3d.com
Thu Jan 12 22:22:49 CST 2017
> On Jan 12, 2017, at 5:34 PM, Greg Parker via swift-evolution <swift-evolution at swift.org> wrote:
>> On Jan 12, 2017, at 4:46 PM, Xiaodi Wu via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>> On Thu, Jan 12, 2017 at 6:27 PM, Jonathan Hull <jhull at gbis.com <mailto:jhull at gbis.com>> wrote:
>>> Also, ‘try’ is still required to explicitly mark a potential error propagation point, which is what it was designed to do. You don’t have ‘try’ with the variants because it is by default no longer a propagation point (unless you make it one explicitly with ’try’).
>> If this is quite safe and more convenient, why then shouldn't it be the behavior for `throws`? (That is, why not just allow people to call throwing functions without `try` and crash if the error isn't caught? It'd be a purely additive proposal that's backwards compatible for all currently compiling code.)
> Swift prefers that potential runtime crash points be visible in the code. You can ignore a thrown error and crash instead, but the code will say `try!`. You can force-unwrap an Optional and crash if it is nil, but the code will say `!`.
> Allowing `try` to be omitted would obscure those crash points from humans reading the code. It would no longer be possible to read call sites and be able to distinguish which ones might crash due to an uncaught error.
> (There are exceptions to this rule. Ordinary arithmetic and array access are checked at runtime, and the default syntax is one that may crash.)
Indirectly Diving by zero  // the compiler won’t let you directly divide by zero
Overflow or underflow 
Array Index out of range
Aside from those, Are there any other runtime “exceptions"?
 https://en.wikipedia.org/wiki/Undefined_(mathematics)#In_arithmetic <https://en.wikipedia.org/wiki/Undefined_(mathematics)#In_arithmetic>
let number = Int16.max
print(number+1) //crash Illegal instruction
> Greg Parker gparker at apple.com <mailto:gparker at apple.com> Runtime Wrangler
> swift-evolution mailing list
> swift-evolution at swift.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution