• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Another thing about java...

xospec1alk

Diamond Member
i have this function
public foo{
public static footype foofunction throws fooexception(...)
}

so im calling foofunction which is supposed to return footype

return foo.foofunction()

but i keep getting an unhandled exception type footype

i put the return in a try catch, but when i catch exception fooexception, what do i put in the body, cause its saying that this function needs to return a footype...
 
alrite alrite....
here is the interface

package timeman.calendar;
ublic interface TimeDuration extends Comparable {
public TimeDuration add(TimeDuration otherTime);
public int getHours();
public int getMinutes();
public int getSeconds();
public int toSeconds();
public TimeDuration subtract(TimeDuration otherTime) throws InvalidTimeOperationException;
public String persistentString();
}

here is the function
final class SimpleTimeDuration implements TimeDuration, Serializable {
public static TimeDuration computeDuration
(TimeOfDay startTime, TimeOfDay endTime)
throws InvalidTimeOperationException {
if (startTime.compareTo(endTime) > 0) {
throw new InvalidTimeOperationException("Cannot compute duration between " +
startTime + " and " + endTime +
", because the start time must be before the end time");
}

TimeDuration timeToStart = new SimpleTimeDuration(startTime);
TimeDuration timeToEnd = new SimpleTimeDuration(endTime);
return timeToEnd.subtract(timeToStart);
}

}

its not the complete class but thats the function i need to access...

InvalidTimeOperationException is given i dont think u need the source for that...

so here, when i try to do

public TimeDuration getDuration(){
SimpleTimeDuration.computeDuration(startTime, endTime) //i get an exception not handled
}// this function is in a whole different class but in the package timeman.calendar
 
Since you do not know what to return in the catch section just declare that the function that calls foofunction also throws fooexception. Now you have passed the buck one level up. That's the beauty of exceptions, you can unwind an error all the way to main if no one knows how to recover from the anomaly.
 
ok in the function

TimeDuration getDuration(){
return SimpleTimeDuration.computeDuration(startTime, endtime);
}

so where exactly am i putting the try/catch?

try{
return SimpleTimeDuration.computeDuration(startTime, endTime);
}catch(InvalidTimeOperationException e) {
// i need to return something of type TimeDuration...but what?
}



 
Back
Top