HomeHome  FAQFAQ  Advertise  SearchSearch  RegisterRegister  Log inLog in  
Advertise Here Just 50$/month
Welcome Here To Our Club Where You Can Discuss About Online Earning from HYIPs, Autosurfs, GPT & Other High-Risk Opportunities
Feel Free To Discuss Just Been Paid Member in Jss Catogeory
Social bookmarking
Social bookmarking Digg  Social bookmarking Delicious  Social bookmarking Reddit  Social bookmarking Stumbleupon  Social bookmarking Slashdot  Social bookmarking Yahoo  Social bookmarking Google  Social bookmarking Blinklist  Social bookmarking Blogmarks  Social bookmarking Technorati  

Bookmark and share the address of Ambrosia on your social bookmarking website
Top posting users this month
banner

Share | 
 

 Error handling for new in C programming

View previous topic View next topic Go down 
AuthorMessage

redrose
Supervisor
Supervisor

Posts : 826
Join date : 2011-10-11
Age : 38
Location : Balaju, Kathmandu

PostSubject: Error handling for new in C programming   Sat Oct 22, 2011 3:37 am

Using new to allocate memory may fail sometimes because of unavailability of memory on the system. To handle the situation there are two methods:
- Exception handling
- no throw method

Exception Handling: new throws exception of type bad_alloc if memory cannot be allocated. So catch this exception. e.g.

try {
int* p = new int [1000000000000000];
} catch (bad_alloc b) {
// Error Messages
}

No throw method is another approach. Use (nothrow) in the call and then check for null-ness of the pointer. E.g.

int* p = new (nothrow) int [10000000000000000];
if ( 0 == p ) {
// Error message
} else {
// Normal execution
Back to top Go down
 

Error handling for new in C programming

View previous topic View next topic Back to top 
Page 1 of 1

 Similar topics

-
» bennett makes another stunning error

Permissions in this forum:You cannot reply to topics in this forum
Ambrosia :: Off Topic section :: Tutorials-
Free forum | © phpBB | Free forum support | Contact | Report an abuse | Forumotion.com