Software Knowledge → 04 · Backend → Error Handling
01
What is it?
Error handling defines what the application should do when something goes wrong.
Good error handling prevents uncontrolled failures and returns useful results.
Simple Definition: Error handling tells the system what to do when an error happens.
02
Think of it like...
Think of an emergency procedure.
When a problem happens, the system follows a planned response instead of failing randomly.
ProblemDetectHandleLogResponse
03
What does it do?
Catch ExceptionsStop unexpected execution from spreading.
Return Error ResponsesExplain failure to the caller.
Log ProblemsRecord useful debugging context.
Protect DataKeep partial work from corrupting state.
Provide Fallback BehaviorChoose a safe alternative path.
Prevent CrashesFail in a controlled way.
04
Where is it used?
Error handling is used in:
API Routes
Services
Database Operations
External API Calls
Background Jobs
File Processing
05
Example
Scenario
Requested order does not exist.
Backend Result
404 Not Found
Response Body
{
"error": "Order not found"
}
06
How it connects
OperationErrorError HandlingLogResponse / Recovery
Error handling turns an unexpected event into a controlled next step.
07
Do Not Confuse
Error Handling
Decides what the system should do.
It may catch an exception, return a response, retry, recover, or stop safely.
Logging
Records information about what happened.
It supports diagnosis, but recording an error alone does not decide the system’s next action.
08
Topic Glossary
| ENGLISH TERM | 中文 | SIMPLE ENGLISH | 中文小白理解 |
|---|
| Error Handling | 错误处理 | Logic used to respond safely when something goes wrong. | 系统发生问题后用于控制和处理错误的一套逻辑。 |
| Error Response | 错误响应 | A response explaining that a request failed. | 后端向客户端返回、说明请求失败的信息。 |
| Exception Handler | 异常处理器 | Code responsible for handling exceptions. | 专门接收并处理异常的代码。 |
| Fallback | 备用处理 | An alternative action used when the normal path fails. | 正常流程失败后使用的替代处理方式。 |
| Recovery | 恢复 | Returning the system to a usable state. | 发生错误后让系统重新进入可正常使用状态。 |
| Graceful Failure | 优雅失败 | Failing in a controlled way without breaking the whole system. | 出错时有控制地返回结果,而不是让整个系统崩溃。 |
09
What to Remember
Error handling makes failures controlled.
It works with exceptions, logs, and responses.
Good error handling helps protect system reliability.