Throwing Errors

suggest change

If you want a function to be able to throw errors, you need to add the throws keyword after the parentheses that hold the arguments:

func errorThrower()throws -> String {}

When you want to throw an error, use the throw keyword:

func errorThrower()throws -> String {
  if true {
    return "True"
  } else {
    // Throwing an error
    throw Error.error 
  }
}

If you want to call a function that can throw an error, you need to use the try keyword in a do block:

do {
  try errorThrower()
}

For more on Swift errors: http://stackoverflow.com/documentation/swift/283/errors#t=201604201738253075092

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents