Skip to main content

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

  1. 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.
  2. Errors cannot be ignored – an uncaught exception terminates the program, while a returned error code may be forgotten by the caller.
  3. 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.
  4. Grouping of error types – different exception types (and class hierarchies) can be caught by different handlers.
  5. Information can be carried – an exception object can carry data about the error (message, value).
  6. Works where return values are not available – constructors and operators have no return value to report an error.
  7. Automatic cleanup – stack unwinding destroys local objects when an exception is thrown, which helps to release resources.
ConventionalException handling
Checks after each callOne handler for a group of statements
Error mixed with logicError code kept separate
Can be ignoredMust be handled or program ends

✓ Answer checked by Claude Opus 5.5 (high effort)

All Object Oriented Programming chapter 10 questions →