Forgive me as it is quite basic, but I want to confirm what's the best way out there. I am creating an instance using "initWith" type of approach, using the designated initializer -
(instancetype)initSignUpParamsWithType:....
In the implementation of the designated initializer it goes something like:
self = [super init];
if (self) {
if (type != requiredType) {
// what needs to be done in this case for raising a proper error?
return nil;
}
self.type = type;
self.username = username;
self.password = password;
Now, in the above method if some param value is NOT what the object seeks, I want to raise an error during the initialization. In Java, we can throw an exception in such cases.
I know we can throw an exception in Objective-C too, but it is not encouraged for such kind of errors. As can be seen discussed here: throwing an exception in objective-c/cocoa
Can someone please guide me to the best practice around this?