Pitching Optional Throws in Swift

In a previous discussion about C++ exception handling, I suggested the introduction of throws! to solve the issue that most C++ functions are needlessly implicitly declared as being able to throw even though most of them will never throw anything. (The discussion then kind of derailed towards discussing other usages for throws!, a very good read!)

How throws! would work is simple: if the caller does not explicitly wrap the call in a try, it'll be implicitly wrapped in a try!. I think it's a much simpler and straightforward way to achieve the goals of this pitch. No need to pass a flag to the callee telling it whether the context is throwing or not and no need to add additional code paths in the callee.

8 Likes