Define an exception type in Swift
//struct error type
struct StructError: ErrorType {
var message: String
}
//class error type
class ClassError: ErrorType {
var message: String
init(message: String) {
self.message = message
}
}
//enum error type
enum EnumError: ErrorType {
case accessDenied, fileNotFound
}
throw StructError(message: "Struct error")
throw ClassError(message: "Class error")
throw EnumError.accessDenied
- Log in to post comments