Learning to handle exceptions properly, knowing when to catch, and when to throw them, is an art. Knowing when it’s a case to retry or to abort a process requires a deep understanding of the problem you’re going to solve.

This code, which Adam found, is a pretty bad example of what to do:

public Collection getPersonsInformation(String department,String function) throws LookupException {
	  ServiceLocator locator = ServiceLocator.getInstance();
	  LookupInterface lookup = locator.getLookupLocal();
	  
	  Collection persons = null;
	 
	  try {
		  persons = lookup.getPersonsInformation(loginInfo, department, function);	
		  
	  } catch(Exception e) {
			return getPersonsInformation(department,function);

	  }
	  return persons;
  }

Any errors on looking up information cause the program to take another crack at getting that information. The only reason this won’t run forever is that the Java stack isn’t good for doing recursion , and will fairly quickly overflow.

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!