Author Topic: CB options  (Read 3333 times)

Offline Turist

  • Single posting newcomer
  • *
  • Posts: 2
CB options
« on: June 29, 2013, 04:26:29 pm »
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.

Code
#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
« Last Edit: June 29, 2013, 04:28:58 pm by Turist »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: CB options
« Reply #1 on: June 29, 2013, 05:11:15 pm »
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!]

Offline Turist

  • Single posting newcomer
  • *
  • Posts: 2
Re: CB options
« Reply #2 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.

Online stahta01

  • Lives here!
  • ****
  • Posts: 7590
    • My Best Post
Re: CB options
« Reply #3 on: June 29, 2013, 11:29:39 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++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org