---
title: "Importance of error handling"
subject: "Object Oriented Analysis and Design"
chapter: 4
key: "semester_6/object_oriented_analysis_and_design:error-handling-importance"
source: https://www.bctengineer.com/q/semester_6/object_oriented_analysis_and_design/error-handling-importance
site: BCT Engineering
---

# Importance of error handling

Object Oriented Analysis and Design · Chapter 4: Implementation

- Asked in: 2070 Magh, 6 marks; 2073 Bhadra, 3+3 marks (asked 2 times)
- Answer checked by Claude Sonnet 5.5 on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_6/object_oriented_analysis_and_design/error-handling-importance
- Whole chapter: https://www.bctengineer.com/md/semester_6/object_oriented_analysis_and_design/chapter-4

## Question

Explain the importance of error handling issues to be resolved in a system. (What are the major functions of exceptions and error handling in program development? Is it required to develop the program? Justify it.)

## Short answer

Error handling with exceptions ensures robustness by separating error logic, propagating faults, protecting resources, and providing meaningful feedback. It is mandatory for reliable software to avoid crashes, data loss, and security holes.

## Answer

**Error handling** is the part of a program that detects errors and exceptional situations at run time and responds to them in a controlled way (recover, retry, report or terminate safely), instead of letting the program crash or produce wrong results. In OO languages it is done with **exceptions** (`try`, `catch`, `finally`, `throw`).

#### Importance (major functions)
1. **Reliability and robustness** - the system continues to work or fails safely when something goes wrong (invalid input, file missing, network failure, divide by zero, database down).
2. **Separation of normal logic from error logic** - the main code remains clean; the error code is in `catch` blocks.
3. **Propagation of errors** - an exception thrown deep in the call stack is passed up to a method that knows how to handle it, avoiding repeated return-code checks.
4. **Protection of data and resources** - `finally` (or try-with-resources) closes files, connections and releases locks, so no leaks or corrupt data.
5. **User-friendly messages and recovery** - the user gets a meaningful message instead of a system crash; the program can retry or use a default.
6. **Debugging and maintenance** - logging stack traces helps find faults.
7. **Security** - avoids leaking internal details and unsafe states.

```java
try {
    int n = Integer.parseInt(input);
    int r = 100 / n;
} catch (NumberFormatException e) {
    System.out.println("Enter a number");
} catch (ArithmeticException e) {
    System.out.println("Cannot divide by zero");
} finally {
    System.out.println("done");   // always runs
}
```

#### Is it required to develop a program?
Yes. Even correct code meets conditions it cannot control (user mistakes, hardware, network). A program without error handling may terminate abruptly, lose data or give wrong answers. Therefore error handling must be planned in design and implemented in every serious system; in some languages (e.g. Java **checked exceptions**) the compiler even forces the programmer to handle them.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What is error handling?
   A. Ignoring run-time problems
   B. Detecting errors at run time and responding in a controlled way
   C. Removing all bugs before release
   D. Printing the source code
   Answer: B. It detects errors and exceptional situations and recovers, reports or terminates safely. (Key point: Purpose of error handling)

2. What is the role of finally or try-with-resources?
   A. Skip errors silently
   B. Throw a new error
   C. Always run to close files and connections and release locks
   D. Restart the program
   Answer: C. Cleanup code in finally runs regardless, preventing leaks and corrupt data. (Key point: Role of finally)

3. How do exceptions help with errors deep in the call stack?
   A. They must be handled where thrown
   B. They pass up to a method that knows how to handle them, avoiding repeated return-code checks
   C. They are ignored
   D. They crash the program
   Answer: B. Propagation lets a suitable higher-level method handle the error, keeping normal code clean. (Key point: Exception propagation)

## Related in Object Oriented Analysis and Design

- [Activities in OO system development](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Aactivities-oo-system-development) — Object Oriented Analysis and Design, chapter 1
- [Exception handling: OO vs conventional](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Aexception-error-handling-oo-vs-conventional) — Object Oriented Analysis and Design, chapter 4
- [External actors and library system sequence diagram](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Aexternal-actors-library-system-sequence-diagram) — Object Oriented Analysis and Design, chapter 2
- [Short note: Distributed system implementation](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Ashort-note-distributed-implementation-issues) — Object Oriented Analysis and Design, chapter 4

## Related in other subjects

- [Steps to develop a computer program](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Asteps-develop-program) — Computer Programming, chapter 2, asked 6×
- [Handling multiple exceptions](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Amultiple-exceptions) — Object Oriented Programming, chapter 10, asked 2×
- [Short note: Major global environmental issues](https://www.bctengineer.com/question.md?key=semester_7%2Ftechnology_environment_and_society%3Aglobal-env-issues-note) — Technology, Environment and Society, chapter 4
- [Short note: Major environment issues of Nepal](https://www.bctengineer.com/question.md?key=semester_7%2Ftechnology_environment_and_society%3Anepal-env-issues-note) — Technology, Environment and Society, chapter 4
