Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error with try catch rethrow...

Status
Not open for further replies.

SwapnilDipankar

Programmer
Mar 27, 2006
2
US
Hi,

The code snippet below works just fine in Linux, but gives me errors when compiled in MSVC++ 6.0. Any thoughts? The code crashes on the line delete pdeOperation;:

int main(int argc, char* argv[]) {
pdeFileOperation *pdeOperation;

try {
pdeOperation = new pdeFileOperation;
} catch(bad_alloc& badAllocError) {
cerr << "Error:: Initializing memory" << endl;
return (EXIT_FAILURE);
} catch(...) {
delete pdeOperation;
cerr << "Error:: Program exited with errors" << endl;
return (EXIT_SUCCESS);
}

pdeOperation->processFiles(0);
delete pdeOperation;

#ifdef _DEBUG_MODE_
cout << "Program exited successfully" << endl;
#endif

return (EXIT_SUCCESS);
}

Cheers!!
-Swapnil
 
Try changing:
Code:
pdeFileOperation *pdeOperation;
to:
Code:
pdeFileOperation *pdeOperation = NULL;
I don't think VC++ 6.0 always throws a bad_alloc exception if new fails, so you might be trying to delete a dangling pointer.
 
Thanks a lot. The suggested solution works just fine. It was a rather lousy mistake at my end.

Cheers!!
-Swapnil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top