Created
March 16, 2016 14:34
-
-
Save Sharrp/bd422ba4d68efe5ff81e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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