Why not throw an exception if [super init] returns nil?

后端 未结 4 2434
北海茫月
北海茫月 2021-02-19 18:15

This is considered typical

- (id)init {
    self = [super init];
    if (self) {
        // <#initializations#>
    }
    return self;
}

4条回答
  •  时光说笑
    2021-02-19 18:50

    No, exceptions in Objective-C are meant for states which you can't really recover from, not just something to show that an operation failed. If you initializer fails, simply return nil to show it.

提交回复
热议问题