---
title: All Catch Blocks Must Log Root Cause
impact: HIGH
impactDescription: enables debugging and incident response
tags: error-handling, logging, debugging, observability, quality, kotlin
---

## All Catch Blocks Must Log Root Cause

Silent failures make debugging impossible. Without proper logging, you cannot trace issues in production.

**Incorrect (silent or minimal logging):**

```kotlin
try {
    processPayment(order)
} catch (e: Exception) {
    // Empty catch - silent failure!
}

try {
    saveUser(user)
} catch (e: Exception) {
    return null // No logging, no context
}
```

**Correct (comprehensive error logging):**

```kotlin
try {
    processPayment(order)
} catch (error: Exception) {
    logger.error("Payment processing failed", error) {
        payload("orderId" to order.id)
        payload("userId" to order.userId)
        payload("amount" to order.amount)
    }
    throw PaymentFailedException("Payment could not be processed", error)
}
```

**Log context should include:**
- Error message and stack trace
- Relevant entity IDs (order, user, etc.)
- Request/correlation ID
- Input that caused the error
- Timing information

**Tools:** Static analyzer, detekt, PR review
