// Customizing error enum RuntimeError: Error { case runtimeError(String) } Example function throws the exception : func someFunction() throws { throw RuntimeError.runtimeError("This error occured at run time.") } // Handling error do { try someFunction() } catch MyError.runtimeError(let errorMessage) { print(errorMessage) }