News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

CB options

Started by Turist, June 29, 2013, 04:26:29 PM

Previous topic - Next topic

Turist

Hello. I try to catch bad_alloc error (if "new" cannot allocate some memory) but program always shut down with "This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information".
With other IDE everything ok.
Can you tell me, what flag or something else i need to use for stable processing "bad_alloc" without shot down program.

#include <cstdlib>
#include <iostream>
#include <new>

using namespace std;

struct T
{
   float Mas[0xFFFFFF];
};

void OutMem()
{
   cout<<"MemOut\n";
   throw(bad_alloc());
}

int main(int argc, char *argv[])
{
   set_new_handler(OutMem);
   try
   {
       T *Arr = new T[0xFFFFFF];
   }
   catch(bad_alloc& e)
   {
       cout<<"ERROR\n";
   }

   system("PAUSE");
   return EXIT_SUCCESS;
}


PS. sorry for my english
PPS windows7 x64

oBFusCATed

1. Start by reading the rules of the forum
2 continue with reading and executing you code by hand (line by line)
3. if you then don't know what is going on read a book about c++.

p.s. because of 1 your topic will be locked...
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Turist

I have read the rules. My question is not related to the code or compiler. Any project, return string as if i use abort(). Flags for my compiler is default as in other IDE , but return values is different. I think this happend by unknown for me, CB behavior. My deep apologise if i mistake.

stahta01

Quote from: Turist on June 29, 2013, 05:40:23 PM
I have read the rules. My question is not related to the code or compiler. Any project, return string as if i use abort(). Flags for my compiler is default as in other IDE , but return values is different. I think this happend by unknown for me, CB behavior. My deep apologise if i mistake.

Read at least some of the FAQs; before you post another post that does NOT belong on this site.
http://wiki.codeblocks.org/index.php?title=FAQ
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]