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

What is low level language in simple words?

0 Answers  


Differentiate between C and C++.

0 Answers   Wipro,


Differentiate between late binding and early binding. What are the advantages of early binding?

0 Answers  


What is a forward referencing and when should it be used?

0 Answers  


What is the difference between new/delete and malloc/free?

1 Answers  






why the size of an empty class is 1

4 Answers  


What are manipulators used for?

0 Answers  


What is lazy initialization in c++?

0 Answers  


Hi i need to Acess a variable "int Intval" in the below mentioned code .How to Access it guys i am waiting for your reply

3 Answers  


Why is c++ is better than c?

0 Answers  


Can a list of string be stored within a two dimensional array?

0 Answers  


what is difference between static and non-static variables

10 Answers  


Categories