Skip to content

Instantly share code, notes, and snippets.

@Sharrp
Created March 16, 2016 14:34
Show Gist options
  • Save Sharrp/bd422ba4d68efe5ff81e to your computer and use it in GitHub Desktop.
Save Sharrp/bd422ba4d68efe5ff81e to your computer and use it in GitHub Desktop.
public func attempt<T>(source source: String = __FUNCTION__, file: String = __FILE__, line: Int = __LINE__, closure: () throws -> T) -> Optional<T>{
do {
return try closure()
} catch {
let fileName = (file as NSString).lastPathComponent
let report = "Error \(fileName):\(source):\(line):\n \(error)"
print(report)
return nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment