Skip to main content

Practice · 2 of 3

Translate at the Boundary

CHALLENGE
Difficulty: intermediate+25 XP

Implement a storage boundary inside Solution: - static class StorageException extends RuntimeException with (String message, Throwable cause) constructor. - static class FlakyStore with static String fetch(String key): returns "data-" + key, but throws IllegalStateException("boom") when the key starts with "!". - static String repositoryGet(String key) — calls fetch and translates any IllegalStateException into StorageException("lookup failed for " + key, e), chaining the original cause. Callers of repositoryGet must never see IllegalStateException.

Back to lesson: Practice: Exception Architecture Lab