为什么一个函数不抛出就满足抛出要求?
Why is a function satisfying a throwing requirement without throwing?
protocol Throwing {
func x() throws
}
class C : Throwing{
func x(){
print("not throwing") // no errors!
}
}
为什么编译器不抛出任何错误?这是设计使然还是错误?
编译的原因是一样的:
class A {
func x() throws {}
}
class B:A {
override func x() {}
}
还有这个:
func f() {}
func yoho (_ f : () throws -> Void) {}
override func viewDidLoad() {
yoho(f)
}
还有这个:
func f() {}
var fun : (() throws -> Void)!
override func viewDidLoad() {
self.fun = f
}
protocol Throwing {
func x() throws
}
class C : Throwing{
func x(){
print("not throwing") // no errors!
}
}
为什么编译器不抛出任何错误?这是设计使然还是错误?
编译的原因是一样的:
class A {
func x() throws {}
}
class B:A {
override func x() {}
}
还有这个:
func f() {}
func yoho (_ f : () throws -> Void) {}
override func viewDidLoad() {
yoho(f)
}
还有这个:
func f() {}
var fun : (() throws -> Void)!
override func viewDidLoad() {
self.fun = f
}