Created
April 22, 2017 23:07
-
-
Save iThinker/689b60a7583ae109f9b789aa98bbba6a 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
class Logger { | |
static var defaultLogger = Logger() | |
func log(_ message: String) { | |
print(message) | |
} | |
} | |
func tryAndLog<T>(_ executable: @autoclosure () throws -> T, withDefault defaultValue: T, logger: Logger = Logger.defaultLogger, file: String = #file, line: Int = #line) -> T { | |
do { | |
return try executable() | |
} | |
catch let error { | |
logger.log("Logged excpetion: \(error.localizedDescription), in \(file), at \(line)") | |
} | |
return defaultValue | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment