Hi all,
We use the http://jedi.codehaus.org libraries for working with collections and manipulating them in a functional way. We recently came across a problem when doing something similar to the following:
public class Address {
//constructors and stuff
public KiloWatts electricityConsumed(Duration timePeriod) throw NoElectricitySupply {
.... does stuff but can throw checked exception
}
}
given we have a collection of addresses and we wanted to perform something on the UnitsOfElectricity associated with each address, how would you handle the thrown exception e.g.:
public KiloWatts totalEnergyConsumed(Address... addresses, final Duration timePeriod) {
List<KiloWatts> energyConsumedPerAddress = FunctionalPrimitives.collect(addresses, new Functor<Address, KiloWatts>{
public KiloWatts execute(Address address){
try {
return address.energyConsumed(timePeriod);
} catch (NoElectricitySupply e) {
//What do you do here?
}
}
});
}
How would you handle the exception?