Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents

Introduction

Good exception design can be useful in communicating the semantics of an operation and improve method factoring. This requires looking beyond the mechanical compilation and to what each method means to its consumer.

...

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.

...

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 don’t want to interfere with the exception chain so this re-throws the same exception.

...

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

Passing The Buck

See Also

...