Error Handling: Writing code that deals with expected problems gracefully, such as showing a useful message, retrying, or logging the issue, instead of crashing or failing silently.
Example
When the payment service is down, your code shows "Payment is temporarily unavailable. Please try again in a few minutes," logs the error with the order ID, and does not mark the order as paid.
Good Error Handling in Practice
- Validate input early and return a clear message, such as "Email is required".
- Catch exceptions where you can do something useful, such as retry or fall back.
- Log the technical details for developers, with enough context to trace the problem. See logging.
- Show users a simple message, never a stack trace.
- Return the right status codes from APIs, such as 400 for bad input and 500 for server errors.
Common Mistakes
| Mistake | Why it hurts |
|---|---|
| Empty catch block | The error disappears and nobody knows something failed |
| Catching every exception everywhere | Hides real problems and makes debugging harder |
| Showing stack traces to users | Confusing for users and a security risk |
| Logging passwords or personal data | A privacy and security problem |
Why Reviewers Care
Most production incidents start with an unexpected input or a service that is down. Code that handles these cases calmly is a sign of a careful developer, and it is one of the first things reviewers look for after correctness.
Related terms
- Exception: the runtime errors you handle.
- Logging: recording errors so they can be investigated.
- Code Quality: good error handling is part of it.
- Debugging: much easier when errors are handled and logged well.
Previous term: Epic | Next term: Escalation
Related guides
- Technical Interview Questions for Freshers
- Java Interview Questions Test
- Python Interview Questions Test
Frequently asked questions
What is error handling?
Error handling is writing code that responds to problems gracefully, such as showing a clear message or retrying, instead of crashing.
What is try-catch?
A structure in many languages that runs code in a try block and handles any exception in a catch block.
Should I catch all exceptions?
No. Catch exceptions where you can handle them usefully, and let others reach a central handler that logs them.
Why is an empty catch block bad?
It hides the error completely, so problems go unnoticed until they cause bigger failures.
Explore more internship terms
The IT Internship Glossary explains 199 terms you will hear before and during your internship, with simple definitions and real examples.
Browse all 199 terms