HomeHome  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 blogmarks  Social bookmarking live      

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

Share | 

 Error handling for new in C programming

View previous topic View next topic Go down 


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

Error handling for new in C programming Empty
PostSubject: Error handling for new in C programming   Error handling for new in C programming I_icon_minitimeSat 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

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