Interview question
How should exceptions be handled differently in development vs production? Development बनाम production में exceptions को अलग तरीके से कैसे handle करें?
Answer
| Aspect | Development | Production |
|---|---|---|
| Error display | Show full stack trace to developer | Never show stack traces or internal messages to users |
| Logging | Optional, console is often enough | Mandatory - log to file, or a service like Sentry/CloudWatch |
| User-facing message | Technical detail is fine | Generic, friendly message plus a reference/error ID |
| HTTP status code | Less critical | Must return the correct status (500, 422, 404, etc.) |
try {
chargeCard($order);
} catch (Throwable $e) {
Log::error($e->getMessage(), ['trace' => $e->getTraceAsString()]);
if (app()->environment('production')) {
return response()->json(['message' => 'Payment failed. Please try again.'], 500);
}
throw $e; // rethrow with full detail locally
}Interview tip: This question tests security awareness as much as PHP knowledge - always mention that leaking stack traces in production can expose file paths, database structure, and even credentials.
| पहलू | Development | Production |
|---|---|---|
| Error display | Developer को पूरा stack trace दिखाएं | Users को कभी stack traces या internal messages न दिखाएं |
| Logging | Optional, console अक्सर काफी है | ज़रूरी - file में log करें, या Sentry/CloudWatch जैसी service |
| User-facing message | Technical detail ठीक है | Generic, friendly message plus एक reference/error ID |
| HTTP status code | कम critical | सही status रिटर्न होना चाहिए (500, 422, 404, आदि) |
try {
chargeCard($order);
} catch (Throwable $e) {
Log::error($e->getMessage(), ['trace' => $e->getTraceAsString()]);
if (app()->environment('production')) {
return response()->json(['message' => 'Payment failed. Please try again.'], 500);
}
throw $e; // locally पूरी डिटेल के साथ rethrow
}इंटरव्यू टिप: यह सवाल PHP knowledge जितना ही security awareness टेस्ट करता है - हमेशा बताएं production में stack traces leak होने से file paths, database structure, और credentials तक expose हो सकते हैं।
Was this answer clear?