Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In most cases, there is no reason to catch org.osid.OsidRuntimeException of any of its subclasses.

Calling Other OSIDs

Exception

...

Misalignment

Sometimes exceptions don’t align and need some attention.

Code Block
languagejava
public class Activity
    implements org.osid.learning.Activity {
    
    private org.osid.id.Id objectiveId;
    private org.osid.learning.ObjectiveLookupSession objectives;
    ...
    @OSID
    public org.osid.id.Id getObjectiveId() {
        return (this.objectiveId);
    }
    
    @OSID 
    public org.osid.learning.Objective getObjective()
        throws org.osid.OperationFailedException {
        
        try {
            return (this.objectives.getObjective(getObjectiveId()));
        } catch (org.osid.DoesNotExistExceptionNotFoundException dnenfe) {
            throw new org.osid.OperationFailedException("for some strange reason, there is no Objective for this Activity. Maybe we're talking to the wrong provider?", dnenfe)
        } catch (org.osid.PermissionDeniedException pde) {
            throw new org.osid.OperationFailedException("for some inexplicable reason you cannot see the Objective for your Activity. Authorization setup is fakakta. ", pde);
        } 
    }
    ...

In the above example, the getObjective() call is implemented using an ObjectiveLookupSession. ObjectiveLookupSession.getObjective defines DoesNotExistException NotFoundtException and PermissionDeniedException not present in Activity.getObjective() (ignoring the unchecked exceptions which imply a programming/integration problem which should not be handled here).

The Activity says that it has an Objective. Therefore, the Objective must exist. To say that Activity.getObjective() should also throw a DoesNotExistException NotFoundException ignores this tenet. If for whatever reason, the provider cannot come up with one should be considered an error due to the result of a breakage in connectivity, data integrity, authorization, configuration, or something which should not occur in normal operations. Semantics like this is what generally causes exception misalignments across method calls.

Do we worry only when exceptions don’t line up?

Exception Alignment

In this case we decided to override the Objective in an orchestration layer.

Code Block
languagejava
public class ObjectiveFetchingActivityLookupSession 
    implements org.osid.learning.ActivityLookupSession {
    
    private org.osid.learning.ActivityLookupSession activityLookupSession;
    private org.osid.learning.ObjectiveLookupSession objectiveLookupSession;
    ...
    @OSID 
    public org.osid.learning.Activity getActivity(org.osid.id.Id activityId) 
        throws org.osid.NotFoundException,
               org.osid.OperationFailedException,
               org.osid.PermsissionDeniedException {
               
        org.osid.learning.Activity activity = this.activityLookupSession.getActivity(activityId);
        org.osid.learning.Objective objective;
        try {
            objective = this.objectiveLookupSession.getObjective(activity.getObjectiveId());
        } catch (org.osid.NotFoundException nfe) {
            throw new org.osid.OperationFailedException("cannot resolve Objective for " + activityId, nfe);
        }
        return (new ObjectiveOverlayActvity(activity, objective);
    }
    ...
        

The first thing this method does is call getActivity() from some underlying provider. It’s similar to the basic decorator/adapter case in the first section. The semantics align so the exceptions align on this call.

The exceptions from getObjective() also align with getActivity(). But the semantics do not. The OSID Consumer is asking for an Activity and to be told the Activity does not exist when the Id reference of the Objective was not found is a problem. The NotFoundException in getActivity() describes the Activity, not the Objective nor any other call this method implementation may use. The fact that we decided to implement this method in such a way to cause this error condition means our service is broken when getObjective() tosses a NotFoundException at us. It should be caught and not allowed to pass through.

Method Factoring

Passing The Buck

...