BeBits Information Developer Central Submit Application Your Account Web Links Contact Us
BeBits
ApiGeneralDesignIssues

Exceptions

I would like to see API wide use of exceptions for errors (where ever possible). I understand that you can't use exceptions in system level code (e.g. kernel), but the 'new' operator already throws an exception if it encounters an error. This makes it difficult to write clean constructors since everything else returns error codes. I think that in general creating objects on the stack (when ever possible) and throwing exceptions makes for cleaner code (at least execution wise). That way if an error is encountered and an exception is thrown the stack is unwound for you automagically and you don't have to worry about empty pointers or orphaned objects. Error code returns from functions seems so 1995 to me. Death to status_t!

Either way, the bottom line is: YOU SHOULD BE CATCHING EXCEPTIONS! The 'new' operator throws them...period.

References:
Using C++ in the kernel
BeNewsletter, Volume III, Issue 51

(I thought there were some articles about exceptions and the 'new' operator, too. Can't find 'em.)
-- Paul J. Stadig

Some info can be found in Effective C++, Item 7.


IndexPage | TableOfContents

PAGE VISITS
3,146

LINKS HERE
IndexPage
ApiDesign

NEW PAGES
CrosscompilingFirefox
BuildingCairo
StoringDataInBetweenOSes
ScriptingBeosRuby
ScriptingBeosPython
HaikuOS
QemUwinbe
MinimalBeos
XpMBRoverwrite
SteveSakoman

RECENT CHANGES
BeUserProfiles
PhilipDybowski
CorumIII
BuildingFirebird
FrontPage
BeAcademic
CrosscompilingFirefox
HowTo
BuildingCairo
BeCommunity
Edit Page | Front Page | BeBits
Site content is in the public domain. Unless otherwise noted, everything else is copyright © 1999-2010 Haikuware. All Rights Reserved.
For more legal trivia, take a gander at our
Legal Stuff page and our Privacy Statement.