...
Code Block | ||
---|---|---|
| ||
class AssetLookupLoggingDecorator
implements org.osid.repository.AssetLookupSession {
private org.osid.repository.AssetLookupSession next;
@OSID
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));
}
... |
...
Code Block | ||
---|---|---|
| ||
class AssetLookupLoggingDecorator implements org.osid.repository.AssetLookupSession { private org.osid.repository.AssetLookupSession next; @OSID 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); } } ... |
...
In most cases, there is no reason to catch org.osid.OsidRuntimeException of any of its subclasses.
Calling Other OSIDs
Exception Alignment
Sometimes exceptions don’t align and need some attention.
Code Block | ||
---|---|---|
| ||
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.DoesNotExistException dne) { throw new org.osid.OperationFailedException("for some strange reason, there is no Objective for this Activity", dne) } catch (org.osid.PermissionDeniedException pde) { throw new org.osid.OperationFailedException("for some inexplicable reason you cannot see the Objective for your Activity", pde); } } ... |
Method Factoring
Passing The Buck
...