Hi, When developing some logic to see if something exists and if it doesn't, then create it, he thinks the following solution is the preferred one:
OurObject obj;
// create a reference to the object if it exists, if it doesn't exist, the method just returns null
obj = someotherobject.somemethodwhichreturnsthe-existingobject(argument)
try {
// next call will throw exception if object was not found in before call
obj.somemethod();
} catch (Exception e) {
// apparently the object did not exist, so let's create it
obj = someobject.createobject(arguments);
}
i think its more correct to do it this way:
OurObject obj;
// create a reference to the object if it exists, if it doesn't exist, the method just returns null
obj = someotherobject.somemethodwhichreturnsthe-existingobject(argument)
if (object == null) {
// apparently the object did not exist, so let's create it
obj = someobject.createobject(arguments);
}
what do you think is better, faster, whatever.
Thanks