Home
131.
Does an exception have to be caught in the same place where the tryblock created the exception?

No, it is possible to catch an exception anywhere in the call stack. As the stack is unwound, the exception is passed up the stack until it is handled.

132.
Why use a debugger when I can use coutand other such statements?

Yes it has difference

The debugger provides a much more powerful mechanism for stepping through your code and watching values change without having to clutter your code with thousands of debugging statements. In addition, there is a significant risk each time you add or remove lines from your code. If you have just removed problems by debugging, and you accidentally delete a real code line when deleting your use of cout, you haven't helped the situation.

133.
What is the difference between the parameterized type of a template function and the parameters to a normal function?

A regular function (nontemplate) takes parameters on which it can take action. A template function enables you to parameterize the type of a particular parameter to the function. That is, you can pass an Arrayof Typeto a function and then have the Typedetermined by the definition of the variable that is an instance of the class for a specific type.

134.
Briefly explain the advantages of inheritance?
  • It permits code reusability
  • It encourages the reuse of proven and debugged highquality software, thus reducing problem after a system becomes functional
  • Reusability saves time in program development
135.
Why use templates when macros will do?

Templates are type-safe and built in to the language, so they are checked by the compiler-at least when you instantiate the class to create a particular variable.

136.
Can a destructor throw an exception?

Technically, yes. However, this is a bad practice as destructors are also called when the stack is unwound due to an exception. So, a destructor invoked due to an exception throwing an exception itself can clearly result in quite an ugly situation for the state of an already unstable application trying to make a clean exit.

137.
My image processing application doesn't respond when it is correcting the contrast. What should I do?

Yes it has difference

It seems that your application does all the activity within one thread. So, if the image processing itself (contrast correction) is processor intensive, the UI is unresponsive. You ought to split these two activities into two threads so that the OS switches the two threads, giving processor time to both the UI and the worker that does the correction.

138.
My multithreaded application allows for extremely fast access to the database. Yet, sometimes I see that the data fetched is garbled. What am I doing wrong?

Your threads are possibly poorly synchronized. You are writing to and reading from an object at the same time, resulting in inconsistent or garbled data recovery. Insert a binary semaphore and ensure that the table cannot be accessed when it is being modified.

139.
What is std::exception?

A class just like any other, but created expressly as a base class for some other exception classes such as bad_alloc.

140.
Is it alright to allocate a million integers in an exception handler (catch block) to back up existing data for instance?

That's a bad idea for it's also possible that the exception was thrown in the first place because of a lack of memory.