Handling returning nil from init
Handling returning nil from init
- Subject: Handling returning nil from init
- From: "Theodore H. Smith" <email@hidden>
- Date: Tue, 12 Jul 2005 15:53:02 +0100
Let's say I have a class which could return nil, from "init" on non-
bug conditions, where the error was a missing-file error or user
configuration error or that sort of thing.
id obj = [[MyClass alloc]init];
if (obj) {
[self DoStuffWith:obj];
}
OK, however, if obj is nil, we'll have leaked it, because we
successfully alloced it.
How do you deal with these situations? Break it down into separate
lines?
id obj1 = [MyClass alloc];
id obj2 = [obj1 init];
if (obj2) {
[self DoStuffWith:obj2];
} else {
[obj1 release];
}
Or is there a more graceful way? Or should init actually release
itself if it has to return nil?
--
http://elfdata.com/plugin/ Industrial strength string processing,
made easy.
"All things are logical. Putting free-will in the slot for premises in
a logical system, makes all of life both understandable, and free."
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden