Versions Compared

Key

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

...

OSIDs strictly define the permissible checked an unchecked exceptions which may pass. They are straightforward in the most basic of method implementations. However, some semantic analysis is necessary when creating a chain of methods to help convey what may have gone wrong to your consumer or ultimately your end user.

Basic Decorator Example

In a decorator pattern (same holds true for adapter patterns across instantiated OSID Providers), the same method is used in both layers. The method signatures line up and more importantly the semantics of the method are identical so the exceptions can just bubble through.

Code Block
languagejava
class AssetLookupLoggingDecorator
    implements org.osid.repository.AssetLookupSession {
    
    private org.osid.repository.AssetLookupSession next;
    
    public org.osid.repository.Asset getAsset(org.osid.id.Id assetId)
        throws org.osid.NotFoundException,
               org.osid.OperationFailedException,
               org.osid.PermissionDeniedException {
           
       log(getEffectiveAgent() + " looking up " + assetId);
       return (this.next.getAsset(assetId));
    }
}     

...

However, there may be a reason to catch an exception or two.

Jumping In The Way

Code Block
languagejava
class AssetLookupLoggingDecorator
    implements org.osid.repository.AssetLookupSession {
    
    private org.osid.repository.AssetLookupSession next;
    
    public org.osid.repository.Asset getAsset(org.osid.id.Id assetId)
        throws org.osid.NotFoundException,
               org.osid.OperationFailedException,
               org.osid.PermissionDeniedException {
           
       try {
           return (this.next.getAsset(assetId));
       } catch (org.osid.OsidException oe) {
           log(getEffectiveAgent() + " could not get " + assetId + " because of " + oe.getMessage());
           throw oe;
       } finally {
           log(getEffectiveAgent() + " looking up " + assetId);
       }
    }
}     

See Also

...