Exception handling !!!

This is a discussion on Exception handling !!! within the C++ Programming forums, part of the General Programming Boards category; ok i just started learning this exception handling thingy and i'm really confusing myself. If exception handling used so we ...

  1. #1
    former member Brain Cell's Avatar
    Join Date
    Feb 2004
    Posts
    472

    Angry Exception handling !!!

    ok i just started learning this exception handling thingy and i'm really confusing myself.

    If exception handling used so we don't have to do error-checking too often , then why do the catch block has to come right after try block? it doesn't make sense to me..

    ok so here are my questions :

    - Do i have to manually throw all exceptions manually or are there exceptions that gets thrown automatically? (like new's bad_alloc fpr example , i'm guessing so i don't know)

    - Whats the difference between :
    Code:
    	try{
    	throw length_error("Error");
    	}
    
    	catch(length_error &c)
    	{
    		cout << c.what() << endl;
    	}
    and
    Code:
    	try{
    	throw "error";
    	}
    	
    	catch(char *str)
    	{
    		cout << str << endl;
    	}
    both work the same way !!!!


    - last question .... what sensitive tasks require exception handling? (other than new)



    any help is appreciated

    this thing is really making me nervous
    Last edited by Brain Cell; 03-08-2005 at 05:52 PM.
    My Tutorials :
    - Bad programming practices in : C
    - C\C++ Tips
    (constrcutive criticism is very welcome)


    - Brain Cell

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Exceptions aren't so you don't have to do the error checking. Its for the situation where the function doesn't know what error handling should occur for a given error.

    For example new. If it fails to allocate memory it throws an exception. Why? Because it doesn't know what you want to do when you encounter that error.

  3. #3
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    I read an article in Dr. Dobbs Jounal about exceptions. They are supposed to be used for things that are beyond your control. Things like no memory available, the user loads a corrupted file, etc.... Things that go wrong with the system, or things that the user does... They should not be used to catch programming bugs.

    Like most casual/hobby programmers, I've never used 'em. AFAIK, the catch block doesn't have to come right after the throw. I sort-of think of exception processing as a special case GOTO. It breaks the normal flow of your program.
    Last edited by DougDbug; 03-08-2005 at 06:34 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. signal handling and exception handling
    By lehe in forum C++ Programming
    Replies: 2
    Last Post: 06-15-2009, 11:01 PM
  2. Exception handling in a large project
    By EVOEx in forum C++ Programming
    Replies: 7
    Last Post: 01-25-2009, 07:33 AM
  3. exception handling
    By coletek in forum C++ Programming
    Replies: 2
    Last Post: 01-12-2009, 05:28 PM
  4. is such exception handling approach good?
    By George2 in forum C++ Programming
    Replies: 8
    Last Post: 12-27-2007, 08:54 AM
  5. Signal and exception handling
    By nts in forum C++ Programming
    Replies: 23
    Last Post: 11-15-2007, 02:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21