Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exceptions vs. classic return ints

Status
Not open for further replies.

McBugzz

Programmer
Joined
Sep 17, 2002
Messages
90
Location
JP
Is there any document that compares C++ exceptions versus ints in return values.

I'm stuck here - some books say: esceptions rule, some say that they cause big apps run slow and make the code less readable.

Where's the truth?
 
The truth is that exceptions rule :-P

1) Exceptions is the only way to return an error from a constructor.

2) With exceptions you can do error handling on a top level without having to pass error codes about. An error that perhaps occured in a class that has no dependacy to GUI stuff and doesn't know how to show something as simple as a message box.

3) I actually think code gets more readable with exceptions because I dont have to deal with error handling when Im digging down in the code. I can always assume success (the file did open and I could allocate buffer and I could read the contents) and leave the rest to error/exception handling.

4) Exceptions forces you (and I think this is good, but some ppl probably disagree) code according to the "allocation is initialization" paradigm. See
These are just couple o' thoughts on the top of my head, but perhaps you could do a google search, like
"C++ exceptions vs return"
to get some more pro/con opinions.


/Per

if (typos) cout << &quot;My fingers are faster than my brain. Sorry for the typos.&quot;;
 
So in the last few days there was a thread on throwing exceptions from destructors. Today we have this issue about exceptions and there effect on the performance of a large scale C++ applications. We get tons of posts from people that want to or are currently developing production applications in C++ that don’t know 10% of what should be considered minimal knowledge for serious use of C++.

There is a secret to becoming a proficient C++ developer that many newbs don’t know…. Shhhhh here it is you have to read and then after that you have to read some more, and then after that…. yes, read some more. Do you see a pattern here?

So here is the single most important book a C++ developer must absolutely read (more than once) and probably own, around $50.00 U.S. new and I have seen it on Amazon used for $28.00, More Effective C++ Scott Meyers 0-201-63371-X

The knowledge in this book, like many others, has become common knowledge and is easily attainable. The only requirement is to remove your fingers from the keyboard and use them to turn the pages of the books. It is just not possible to achieve the same level of knowledge by spending 20 hours a day hacking out some of the worst code in the history of man kind. There, another myth dispelled.

As to the current subject and all the myths surrounding it, that book contains 5 sections, of the 35, regarding exceptions.


-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top