Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Jul 28th, 2006, 9:29 AM   #7
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Quote:
Originally Posted by lectricpharaoh
I agree with MBirchmeier. They are nice to have, and go a long way to writing robust code. However, the performance is usually much slower than simply checking a flag or return value, and as such, they shouldn't be used for most operations. For example, when opening a file, it seems nonsensical to throw an exception if the file cannot be opened; instead, return a success/failure code like the C standard library does.
I strongly disagree with this recommendation.

Firstly, the performance overhead would only make a significant difference if one were expecting exceptions to be thrown on a regular basis. If you throw exceptions only in exceptional circumstances (as the name "exceptions" suggests), then any performance degredation is going to be negligible at best.

Further, exceptions have several advantages over return values. From a structural point of view, they cleanly separate the concept of return values from errors and warnings. From a practical point of view, they automatically propagate up the stack until they are caught, so the programmer need only deal with the error once, rather than construct an elaborate chain of return values, or a singleton/global variable to hold error information. Finally, languages like Java throw compile errors at uncaught exceptions, preventing possible bugs.

In any unusual or exceptional circumstance, exceptions should be used. Return values should not, in my opinion, be used for anything other than returning valid data.
Arevos is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA-if statements Quagmire Visual Basic 3 Feb 17th, 2006 2:44 PM
Catch command line output SoniX Visual Basic .NET 1 Jan 22nd, 2006 6:25 AM
Try without catch JavaDummy Java 4 Jul 30th, 2005 4:20 PM
Multiple IF statements, perhaps? foxcity911 PHP 7 Jun 22nd, 2005 3:33 PM
Code annoyance, variables not available outside of if statements? Arla C# 15 May 24th, 2005 8:53 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:43 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC