Exception handling vs. return values to signal an error

Why we would use exception handling rather than different return values to signal an error?

Questions by langleq9

Showing Answers 1 - 12 of 12 Answers

jeetsahu

  • Jul 16th, 2008
 

exception are not errors in true sense,

through exception handling we can handle that exception but by returning values we cannot handle that error.

generally exception occurs when logic and syntax is also correct but in some cases it does not give desired output

thumbeti

  • Nov 1st, 2009
 

Using exceptions, it becomes easy to pass multiple types of values from a single function. Handling the exceptions is hirachical.

If we dont have exceptions, it will be difficult to return multiple values from a function.

  Was this answer useful?  Yes

ajrobb

  • Sep 22nd, 2010
 

When programs throw and exception, control is transferred to the innermost matching catch statement. If the exception is not caught with the program, the program terminates. All automatic variables are cleaned up first. It is NOT required that every function call has its return value examined and is surrounded by error-handling source code. However, the compiler-generated object code to clean up the automatic variables can make the executable much larger.

Leaf routines that do not throw exceptions nor call routines that throw exceptions can be labelled with throw() to help the compiler. If a routine can only throw a few types of exception, these can be ennumerated in the definition/declaration. Other types of exception become fatal and dump core. If a function is not declared with a throw list, it can throw any exception.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions