Subjects

All subjects Django Java Python React Spring Boot JavaScript PHP
Sign Up Free
Question 9 of 10 · Error & Exception Handling
Interview question

How should exceptions be handled differently in development vs production? Development बनाम production में exceptions को अलग तरीके से कैसे handle करें?

Answer
AspectDevelopmentProduction
Error displayShow full stack trace to developerNever show stack traces or internal messages to users
LoggingOptional, console is often enoughMandatory - log to file, or a service like Sentry/CloudWatch
User-facing messageTechnical detail is fineGeneric, friendly message plus a reference/error ID
HTTP status codeLess criticalMust 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.

पहलूDevelopmentProduction
Error displayDeveloper को पूरा stack trace दिखाएंUsers को कभी stack traces या internal messages न दिखाएं
LoggingOptional, console अक्सर काफी हैज़रूरी - file में log करें, या Sentry/CloudWatch जैसी service
User-facing messageTechnical 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?