15.4 Calling Throwing Methods and Functions
Once a method or function is declared as throwing errors, it can no longer be called in the usual manner. Calls to such methods must now be prefixed by the try statement as follows:
try fileTransfer()
In addition to using the try statement, the call must also be made from within a do-catch statement to catch and handle any errors that may be thrown. Consider, for example, that the fileTransfer method needs to be called from within a method named sendFile. The code within this method might be implemented as follows:
func sendFile() -> String {
do {
try fileTransfer()
} catch FileTransferError.noConnection {
return("No Network Connection")
} catch FileTransferError.lowBandwidth {
...