---
title: "Exception and error testing"
subject: "Software Engineering"
chapter: 8
key: "semester_5/software_engineering:exception-error-testing"
source: https://www.bctengineer.com/q/semester_5/software_engineering/exception-error-testing
site: BCT Engineering
---

# Exception and error testing

Software Engineering · Chapter 8: Software Testing and cost Estimation

- Asked in: year not given, 5 marks
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_5/software_engineering/exception-error-testing
- Whole chapter: https://www.bctengineer.com/md/semester_5/software_engineering/chapter-8

## Question

What is exception and error testing?

## Answer

**Exception and error testing** (error-handling testing) checks that the software detects abnormal conditions and handles them correctly: it should report a clear message, protect data, and either recover or fail safely, instead of crashing or producing wrong results. A well-designed program anticipates errors and has error-handling paths, and these paths must be tested just like normal paths.

#### What is tested
- **Invalid inputs**: wrong type, out-of-range values, empty fields, very long strings.
- **Exceptions thrown by code**: divide by zero, null reference, array index out of bounds, file not found, overflow.
- **External failures**: database or network down, disk full, time-out, hardware failure.
- **Recovery**: after the error, the system returns to a consistent state (transactions rolled back, resources released).

#### Typical error-handling faults (Pressman)
1. The error description is unintelligible to the user.
2. The error noted does not match the error actually encountered.
3. The error condition causes system intervention (crash) before error handling runs.
4. Exception-condition processing is incorrect.
5. The error description does not give enough information to find the cause.

#### Techniques
- Use **invalid equivalence classes and boundary values** as test inputs.
- **Fault injection**: deliberately cause failures (e.g. disconnect the database) to see how the system reacts.
- **White-box coverage** of every `catch`/error branch.
- **Recovery testing**: force the software to fail and check that it recovers within the required time.
- Unit-test frameworks can assert that an exception is thrown, e.g. JUnit `assertThrows(ArithmeticException.class, () -> divide(5, 0))`.

#### Example
In a bank transfer feature:

| Test | Expected handling |
|---|---|
| Amount = −500 | "Invalid amount" message, no transfer |
| Amount > balance | "Insufficient balance", balance unchanged |
| Network drops mid-transfer | Transaction rolled back, user informed |
| Wrong account number | "Account not found" message |

Exception and error testing improves **robustness and reliability**, since many real failures come from conditions that the normal tests never exercise.

## Check yourself

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

1. What does exception and error testing check?
   A. That abnormal conditions are detected and handled safely, with clear messages and data protection
   B. That the program never receives invalid input
   C. That normal paths run faster
   D. That the user interface looks pleasing
   Answer: A. Error-handling paths must be tested like normal paths so the system reports, recovers or fails safely instead of crashing. (Key point: Purpose of error testing)

2. What is fault injection?
   A. Adding extra features to the code
   B. Deliberately causing failures, e.g. disconnecting the database, to see how the system reacts
   C. Fixing faults without testing
   D. Randomly deleting test cases
   Answer: B. Fault injection forces failures to observe the system's error handling and recovery. (Key point: Fault injection)

3. In the bank transfer example, the network drops mid-transfer. What is the expected handling?
   A. Complete the transfer anyway
   B. Crash and restart without notice
   C. Ignore the error and show success
   D. Roll the transaction back and inform the user
   Answer: D. After an error the system should return to a consistent state, e.g. roll back the transaction, and inform the user. (Key point: Recovery after an error)

## Related in other subjects

- [Exception handling over conventional error handling](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Aexception-advantages) — Object Oriented Programming, chapter 10
- [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
- [Types of error; single proportion test](https://www.bctengineer.com/question.md?key=semester_5%2Fprobability_and_statistics%3Asingle-proportion-types-of-error) — Probability and Statistics, chapter 7, asked 2×
