Are there are any performance cost by creating, throwing and catching exceptions in Java?
I am planing to add \'exception driven development\' into a larger project.
As per your last edit. I think ( as Tony suggested ) using the NullObject pattern would be more useful here.
Consider this third scenario:
class NullUser extends User {
public static NullUser nullUser = new NullUser();
private NullUser(){}
public int getAge() {
return 0;
}
}
//Later...
int age;
User user = getUser("adam"); // return nullUser if not found.
age = user.getAge(); // no catch, no if/null check, pure polymorphism