Why this matters
External systems fail unpredictably; explicit handling avoids crashes and improves resilience.
Surround network and IPC calls with try/catch for IOException and timeouts; map to domain errors and log context.
External systems fail unpredictably; explicit handling avoids crashes and improves resilience.
Side-by-side examples engineers can pattern-match during review.
val body = http.get(url).body.string()try {
val body = http.get(url)
handle(body)
} catch (e: IOException) {
logger.error("http failed", mapOf("url" to url, "err" to e))
return Result.failure(e)
}client.execute(req).body!!try { client.execute(req) } catch (e: IOException) { /* map/log */ }From the same buckets as this rule.
Check if loops use equality operators (== or !=) in termination conditions. These can lead to infinite loops if the condition is never met exactly. Instead, use relational operators like < or > for safer loop termination.