is throwing exception from a constructor not a good practice ?
Answers were Sorted based on User's Feedback
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 |
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 |
Answer / dps
ya its better i think because it will take less memory and
less time
| Is This Answer Correct ? | 0 Yes | 0 No |
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 |
Answer / saranya
yes, because constructor does not throws an exception
| Is This Answer Correct ? | 1 Yes | 8 No |
Why can you not make a constructor as const?
What is the difference between containment and delegation?
Why are pointers used?
string somestring ; Which of the following choices will convert a standard C++ string object "somestring" to a C string? a) Copy.somestring () ; b) somestring.c_str () c) &somestring [1] d) std::cstring (somestring) e) (char *) somestring
Write a Program to find the largest of 4 no using macros.
why we cant create array of refrences
What is the difference between an external iterator and an internal iterator?
When should you use multiple inheritance?
What happens if a pointer is deleted twice?
Do we have to use initialization list in spite of the assignment in constructors?
Can circle be called an ellipse?
Define stacks. Provide an example where they are useful.