Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A generic error I use in Swift, typically for cases that are not intended to be dealt with in a manner other than being logged
struct GenericError: Error, CustomStringConvertible, CustomDebugStringConvertible, Equatable, Codable {
let description: String
let file: String
let function: String
let line: Int
init(message m: String, file f: String = #file, function n: String = #function, line l: Int = #line) {
description = m; file = f; function = n; line = l
}
var debugDescription: String {
/* this looks like: file.swift:1 function(parameter:) "description" */
return "\(file):\(line) \(function) \"\(description)\""
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment