Thread: Throwing an exception in int main()

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Quote Originally Posted by CornedBee View Post
    Crashing is just one form of terminating.
    ... Oh, ok. I just figured that "termination" means "user-friendly program exit".
    Devoted my life to programming...

  2. #2
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    All my main() functions look the same:
    Code:
    int main(int argc, char** argv) 
    {
    	using namespace std;
    	try {
    		return main_program(argc,argv);
    	}
    	catch (runtime_error& e) {
    		cerr << RED << "Run-time error : " << e.what() << NORMAL << endl;
    	}
    	catch (bad_alloc&) {
    		statusFailed();
    		cerr << RED << "Out of memory." << NORMAL << endl;
    	}
    	catch (exception& e) {
    		cerr << RED << "Exception : " << e.what() << NORMAL << endl;
    	}
    	catch (...) {
    		cerr << RED << "Unknown error" << NORMAL << endl;
    	}
    	return 1;
    }
    Then main_program takes the role of the main function.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting Issue?
    By matthewlane in forum C Programming
    Replies: 1
    Last Post: 11-15-2010, 05:55 PM
  2. Drawing Program
    By Max_Payne in forum C++ Programming
    Replies: 21
    Last Post: 12-21-2007, 05:34 PM
  3. Replies: 26
    Last Post: 11-30-2007, 03:51 AM
  4. Switch/case Problems (long code in post)
    By Wraithan in forum C++ Programming
    Replies: 2
    Last Post: 12-01-2005, 06:40 PM
  5. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM