- 2068 Chaitra · 3 marks
Exception handling over conventional error handling
Short answer
Exception handling separates error code from normal logic, ensures errors cannot be ignored, propagates automatically, groups error types, carries data, works for constructors/operators, and uses stack unwinding to release resources.
What are the advantages of Exception Handling over Conventional Error Handling mechanism?
Conventional error handling uses return codes, global error variables (errno) and if checks after every call. Exception handling separates error handling from normal code.
Advantages of exception handling
- Separation of error code from normal logic – the try block holds the normal flow and catch blocks hold the error handling, so the program is easier to read.
- Errors cannot be ignored – an uncaught exception terminates the program, while a returned error code may be forgotten by the caller.
- Propagation to the right level – an exception passes up the call chain automatically until a handler is found; with return codes every function in between must check and pass the code.
- Grouping of error types – different exception types (and class hierarchies) can be caught by different handlers.
- Information can be carried – an exception object can carry data about the error (message, value).
- Works where return values are not available – constructors and operators have no return value to report an error.
- Automatic cleanup – stack unwinding destroys local objects when an exception is thrown, which helps to release resources.
| Conventional | Exception handling |
|---|---|
| Checks after each call | One handler for a group of statements |
| Error mixed with logic | Error code kept separate |
| Can be ignored | Must be handled or program ends |
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Exception handling constructs · Object Oriented Programming, chapter 10 · asked 4×
- Re-throwing an exception · Object Oriented Programming, chapter 10
- Exception handling: OO vs conventional · Object Oriented Analysis and Design, chapter 4
- Exception and error testing · Software Engineering, chapter 8
- Importance of error handling · Object Oriented Analysis and Design, chapter 4 · asked 2×