C++

Topic: Exceptions

Explain about Implications of Using Exceptions with example ?

To support exceptions and stack-unwinding, the process of calling destructors on leaving a scope, compilers put in some initialization code to ensure that if a routine may return via an exception it will properly call destructors. This seems to imply that stack-unwinding is a big part of the fixed cost regardless of whether or not you use a try/catch block. Even if you only use primitive types, if you make calls to functions, which is highly likely, then you probably end up paying this cost. So it is probably best to assume that this fixed cost is a part of the cost of a function call, and potentially, scope change if that scope change has local variables.This means there is additional code being executed. This can consist of function calls that the compiler automatically inserts into the code. Some compilers may allow this code to be generated inline to improve performance, such as C++ Builder. So if we are probably going to be paying this cost, then why worry about how many try/catch blocks there are? Because it is best to partition error handling code from regular execution code. This keeps the intent of the code clear.Another important fact about exceptions is that they affect program flow control. This is very significant particularly during the debugging process. A thrown exception can transfer control to a catch in a very distant location as well as, of course all the way up to main(). This can wreak havoc with figuring out the origin of the exception. Just consider this innocuous source listing:try   {   SomeFunc();     AnotherFunc( 16 );   YetAnotherFunc( EvenMoreFunctions( 2 ) );   }catch(...)   {   // catch all exceptions and cleanup     throw;   }Now try debugging this when an exception is generated by a function that EvenMoreFunctions() calls. And it only happens some of the time. Granted, if you're in a debugger you can just enable the 'Break on C++ Exception' option and viola. However, if this a bug report from a tester, or worse, customer, and it rarely happens, well then you have some trouble.It is not just the throw of an exception which impacts program flow control. The catch clause or more specifically, clauses can have a significant effect as well. When the exception is thrown it will be transferred to the first matching catch block of the exception type thrown. This can be conceptualized as a special kind of switch statement; and a switch statement affects flow control.

Browse random answers:

What is Exceptions in c++ ?
Can we generate a C++ source code from the binary file?
what is Un handled exception(KERNEL32.DLL):0xE06D7363 in the context of exception handling? pls answer to my mail id.in the flg code i got a problem.i want to know the entire steps followed in exception handling in this program.#include <iostream>using namespace std;int main(){ cout << "Start"; try  { // start a try block cout << "Inside try block"; cout << "Still inside try block"; throw 78; } catch (double i)  { // catch an error cout << "Caught an exception -- value is: "; cout << i << ""; } cout << "End"; return 0;}
How does throwing and catching exceptions differ from using setjmp and longjmp?
what is the difference betwen wait() and delay()?
How can I get around scope problems in a try/catch?
Explain exception specifications with example ?
Explain about standard exceptions with example ?
Explain about try, catch, and throw Statements (C++) ?
Exceptions are hard to ignore, unlike error codes. ?
What are C++ Exception  Examples ?
Explain about Unhandled C++ Exceptions ?
Explain about exception Handling Overhead ?
Explain about Mixing C (Structured) and C++ Exceptions ?
Explain about Overview of C++ Exception Handling with example ?
Explain about Implications of Using Exceptions with example ?
Explain about Designing With Exceptions with example ?
Explain about exceptions in Real-Time Systems ?
Explain about exception Handling Philosophies with example ?
Explain about exceptions in an Array-Based Stack ?
How many exceptions in a List-Based Stack ?
What are some ways try / catch / throw can improve software quality? 
How do exceptions simplify my function return type and parameter types? 
What does it mean that exceptions separate the "good path" (or "happy path") from the "bad path"? 
Exception handling seems to make my life more difficult; clearly I'm not the problem, am I?? 
How can I handle a destructor that fails? 
How can I handle a constructor that fails? 
How should I handle resources if my constructors may throw exceptions? 
What is exception-safe code? 
Explain about exception Neutrality ?
Explain how we implement exception handling in C++  
Explain terminate() and unexpected() function  ?
Exception handling concept  ?
Describe the way to handle run time error in C++.