Thread: Bad_alloc exception in under Linux?

  1. #1
    wickdgin
    Guest

    Bad_alloc exception in under Linux?

    I was compilling a school assignment that I had done in Visual C++ on my home computer running Slackware 8.1 w/ gcc 2.95.3

    Anyway, I used the 'bad_alloc' exception thrown by the system when there is no more space to be allocated to the heap.

    I was wondering what I could use as an equalivent on my Linux system.

    The code runs and compiles fine without the lines using that exception.

  2. #2
    wickdgin
    Guest
    The compiler supports exceptions fine... my own user defined exceptions work perfectly.

    Code:
    template<class ItemType>
    const bool BST3<ItemType>::IsFull(){
    	/*****
    	Tests if tree is full by catching the bad_alloc() exception
    		bad_alloc() exception is thrown if no memory is available for data
    		to be allocated
    	******/
    
    
    	try{
    		BST3_node* temp_ptr;
    
    		temp_ptr = new BST3_node;	//Check for one node allocation
    		delete temp_ptr;
    	}
    	catch(	bad_alloc error	){	return true;  }
    
    
    	return false;
    }
    There is an example of an IsFull function for a binary search tree I did for my non-linear data structures class. All compiles and runs fine under vC++ 6.0 -- and compiles fine with gcc/g++ 2.96 if I remove the lines that catch the bad_alloc.


    Code tags amended by Hammer

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Thinking of upgrading to linux...
    By Yarin in forum General Discussions
    Replies: 37
    Last Post: 07-24-2009, 11:40 AM
  2. Wireless Network Linux & C Testbed
    By james457 in forum Networking/Device Communication
    Replies: 3
    Last Post: 06-11-2009, 11:03 AM
  3. Dabbling with Linux.
    By Hunter2 in forum Tech Board
    Replies: 21
    Last Post: 04-21-2005, 04:17 PM
  4. installing linux for the first time
    By Micko in forum Tech Board
    Replies: 9
    Last Post: 12-06-2004, 05:15 AM