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 //
Home » 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 //
At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.
See our full editorial policy.