General purpose to make a concrete Error instance in Swift
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
// | |
// ZError.swift | |
// ZKit | |
// | |
// Created by Kaz Yoshikawa on 7/18/22. | |
// | |
// Usage: | |
// General usage for throwing Error in Swift language. | |
// | |
// Example: | |
// guard let number = number else { throw ZError("number should not be nil.") } | |
import Foundation | |
struct ZError: Error, CustomStringConvertible { | |
let message: String | |
let fileID: String | |
let function: String | |
let line: Int | |
init(_ message: String, fileID: String = #fileID, function: String = #function, line: Int = #line) { | |
self.message = message | |
self.fileID = fileID | |
self.function = function | |
self.line = line | |
} | |
var description: String { | |
return "\(message): \(fileID), \(function)(\(line)" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment