What if memory allocation using new fails in C++ how to handle



What if memory allocation using new fails in C++ how to handle..

Answer / Abhay Mishra

"When memory allocation using 'new' fails in C++, it throws a 'bad_alloc' exception. To handle this exception, you can use try-catch blocks as follows:n1. Enclose the code that allocates memory inside a 'try' block.n2. Define a 'catch(bad_alloc)' block to catch the exception.n3. Write your error handling code inside the catch block."n

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Java J2EE Interview Questions

how to measure method execution time in java

1 Answers  


BIG-O NOTATIONS

1 Answers  


What if memory allocation using new fails in C++ how to handle

1 Answers  


Check Your Java OOPs Concepts Skills and Master it Quickly

1 Answers  


Creating Class and methods – Java OOP Exercise

1 Answers  


Find Best Job Vacancies across the world on Jooble!

0 Answers  


Distance between two points in java

1 Answers  


ALL OOPs Concepts Using Java with 1 Tiny Program – Explained!

1 Answers  


Categories