Versions Compared

Key

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

...

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);
        }
    }
...    

We This method adds nothing to the process of retrieving an asset so we don’t want to interfere with the exception chain so this re-throws . Re-throwing the same exception instead of creating a new one is the right choice when just needing a sneak peek.

This could have caught each of the NotFoundException, OperationFailedException, and PermissionDeniedException explicitly, but OsidException was a bit easier. All org.osid.OsidExceptions are checked exceptions declared in the method signatures. We cannot get any other kind of checked exception from getAsset() so the broader net is fine in this case (note that org.osid.OsidRuntimeException is like java.lang.RuntimeException but org.osid.OsidException is not like java.lang.Exception because it does not include org.osid.OsidRuntimeExceptions).

...