devxlogo

Do Not Use Operator New in a Throw Statement

Do Not Use Operator New in a Throw Statement

Dynamic allocation of an exception (as in this example) is not a good idea:

 class Err{public:   Err(const char * description);};void f(){  if (disaster)    throw new Err("failed");  //exception object is dynamically allocated on the free store  //

devx-admin

Share the Post: