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  //

Share the Post:
Share on facebook
Share on twitter
Share on linkedin


Recent Articles: