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 :
cout << c.what() << endl;
both work the same way :mad: !!!!
cout << str << endl;
- last question .... what sensitive tasks require exception handling? (other than new)
any help is appreciated
this thing is really making me nervous
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.
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. :D 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.