Skip to content

Instantly share code, notes, and snippets.

Created July 18, 2022 19:22
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
General purpose to make a concrete Error instance in Swift
// 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