is throwing exception from a constructor not a good practice ?

Answers were Sorted based on User's Feedback



is throwing exception from a constructor not a good practice ?..

Answer / vikas sood

throwing exception from a constructor is not bad at all. It
is actually advised to use exceptions when you fail to
create your object properly due to any reason. In this case
memory will not be allocated for the object and no
destructor will be called.

Is This Answer Correct ?    11 Yes 1 No

is throwing exception from a constructor not a good practice ?..

Answer / manjunath

Throwing a exception from constructor is perfectly good
habit. That is how to handle errors in the constructor.
Smart pointers can also be used in this scenario.

Is This Answer Correct ?    4 Yes 1 No

is throwing exception from a constructor not a good practice ?..

Answer / dps

ya its better i think because it will take less memory and
less time

Is This Answer Correct ?    0 Yes 0 No

is throwing exception from a constructor not a good practice ?..

Answer / shwetha.v.g

Actualy though when an object is created memory will b
allocated but the process of allocation of memory will be
complete only if conytructor is successfully invoked so if
constructor throws an exception memory will not be
allocated for that object.

Is This Answer Correct ?    1 Yes 6 No

is throwing exception from a constructor not a good practice ?..

Answer / saranya

yes, because constructor does not throws an exception

Is This Answer Correct ?    1 Yes 8 No

Post New Answer

More C++ General Interview Questions

Will rust take over c++?

0 Answers  


What is the best c c++ compiler for windows?

0 Answers  


Why is c++ still used?

0 Answers  


Write a program using GUI concept for the scheduling algorithms in Operating system like SJF,FCFS etc..

0 Answers  


What does '\r' and '\b' mean? Please explain with example.

7 Answers  


Describe about storage allocation and scope of global, extern, static, local and register variables?

0 Answers  


Write a function which takes a character array as input and reverses it in place.

2 Answers   Lehman Brothers, Vision Infotech,


What is difference between class and structure in c++?

0 Answers  


Define the process of error-handling in case of constructor failure?

0 Answers  


What things would you remember while making an interface?

0 Answers  


Why do we need runtime polymorphism in c++?

0 Answers  


Write a note about the virtual member function?

0 Answers  


Categories