Click here to Skip to main content
15,922,166 members

Survey Results

How do you return error conditions?   [Edit]

Survey period: 16 Apr 2007 to 22 Apr 2007

If a routine encounters an error do you hope the caller checks, or do you throw an exception to force the point? (inspired by Anna's blog)

Q1. For non-critical errors:

OptionVotes% 
Set a global error flag222.40
Return a reserved value (0 or -1 etc)27830.32
Return an encoded error value (eg HRESULT)14716.03
Throw an exception37340.68
Cover up the mess and don't say anything9710.58

View optional text answers (23 answers)
Q2. For critical errors that leave the app in an undefined state

OptionVotes% 
Set a global error flag444.80
Return a reserved value (0 or -1 etc)566.11
Return an encoded error value (eg HRESULT)626.76
Throw an exception69776.01
Cover up the mess and don't say anything505.45

View optional text answers (26 answers)


 
GeneralRe: ...unless you are using C++ Pin
Chris Losinger17-Apr-07 7:07
professionalChris Losinger17-Apr-07 7:07 
GeneralRe: ...unless you are using C++ Pin
Blake Miller17-Apr-07 9:09
Blake Miller17-Apr-07 9:09 
GeneralRe: ...unless you are using C++ Pin
Shog916-Apr-07 15:02
sitebuilderShog916-Apr-07 15:02 
GeneralRe: ...unless you are using C++ Pin
peterchen16-Apr-07 23:36
peterchen16-Apr-07 23:36 
GeneralRe: ...unless you are using C++ Pin
Shog917-Apr-07 5:37
sitebuilderShog917-Apr-07 5:37 
GeneralRe: ...unless you are using C++ Pin
peterchen17-Apr-07 7:32
peterchen17-Apr-07 7:32 
GeneralRe: ...unless you are using C++ Pin
Shog917-Apr-07 8:08
sitebuilderShog917-Apr-07 8:08 
GeneralRe: Exceptions are good [modified] Pin
User of Users Group17-Apr-07 13:06
User of Users Group17-Apr-07 13:06 
In hasty response, sales of exception-safe code before and after Sutter-era journalism did nothing to prove such code is:

a) around aplenty
b) performs better
c) is more maintainable
d) appropriate for component-based development in C++

While I am slightly worried to see ATL roots here acknowledging the fact exceptions can produce more readable and maintainable code, I must agree with it if you look at that fragment (readable, maintainable), word by word. But not any further than that.

All I can do is give my short and uninformed story:

For one, a lot of effort went into exception-less STL and platforms that had no compiler or runtime support. Same goes for ATL and WTL I guess.

The following one is not on checked access, but on checked concepts, one of them being iterators are priceless as they can report subtle errors no exception or errorcode-based code can resolve - logic bugs.

Writing service or system software was done in C (until Vista I guess), and huge body of work went into it. People still argue on specification lists and what if any of exception-related information should be in the metadata.

Lastly, no exception hype or book or next modern mechanism can protect against exceptional circumstances of OS, security, network or any other type of 'integrity' failure. Attempting to use C++ as a tool for transactional programming (be that replication work before moving on to compiler team or not), without expecting C like and MTS like interfaces is, in my mind, a good waste of time.

If you are attempting to save your application state, than you might as well do a differential backup, continuous backup, pre-allocate storage, and do whatever you were going to do with exceptions because they will not help you much more once you hit the 'exceptional circumstances'.

Heard of : 'Program encountered an error. Please save your work', only to see the Save operation initiate a crash of the system?

Exceptions do not improve availability either, and I could argue they disable plenty of optimisations new (re:copy of old) hardware architectures are providing.

Examples:

MS Word crashes with or without exceptions.

IE too.

SQL Server reports rejection on overload, do you as a client bomb out too?

Your OS becomes unresponsive any time it deals with any good file manipulation, do you bomb out?

And who do you bomb out to?

Simply the next 'manager' that is very likely to bomb out, and so the story goes all the way down to halt or blue screen (or your system requires administration anyway, like restart).

That is how most software works, and exceptions are just an implementation detail that makes a lot of overhead in service-based or OS software.

Having criticised exceptions for time I have for the discussion, I can see a good use to them if you are looking out for integrity hype that exceptions never achieved. The best possible use I can see to them is in deep 'inner scope' of a function, making programming/interfacing to 3rd party components clean and lazy (as in simplified error checks).

The fact is if you do not understand a large number of conditions or values you might be hit with, or have provisioned for them to a 'good enough' extent, you are more likely to have an event tracing use rather than an exception use in your code (see the trend in all software overwhelming your Event Log with information).

Using a catch all clause can help against further corruption sure, but if you know those values why not record them or better handle them so your system is in maintenance mode for you to see, rather than having it obscured in a complex 'unwinding interaction'.

Besides, you know it all ducks when those slow CLR dialogs appear, especially on floating point arithmetic, bad XML, and file manipulation.

And, quite frankly, ‘The Power Of None’ seems like another attempt at template masturbation while another X systems and runtimes are on your path, on a daily basis, on a another piece of unreadable Martian writing.

Less code is better, but less code is ‘other’ services too, not just exceptions.

Example: what NX bit did for C code.

Sincerely,
6


-- modified at 19:19 Tuesday 17th April, 2007
GeneralExceptions are evil Pin
Michael Dunn15-Apr-07 18:30
sitebuilderMichael Dunn15-Apr-07 18:30 
Generallongjmp() all the way! Pin
Shog915-Apr-07 19:12
sitebuilderShog915-Apr-07 19:12 
GeneralRe: longjmp() all the way! Pin
Gary Wheeler16-Apr-07 2:24
Gary Wheeler16-Apr-07 2:24 
GeneralRe: longjmp() all the way! Pin
John R. Shaw16-Apr-07 7:11
John R. Shaw16-Apr-07 7:11 
GeneralRe: longjmp() all the way! Pin
Gevorg17-Apr-07 5:37
Gevorg17-Apr-07 5:37 
GeneralRe: longjmp() all the way! Pin
Shog917-Apr-07 5:52
sitebuilderShog917-Apr-07 5:52 
GeneralRe: Exceptions are evil Pin
Nemanja Trifunovic16-Apr-07 2:01
Nemanja Trifunovic16-Apr-07 2:01 
GeneralEvent log Pin
Nisamudheen15-Apr-07 18:14
Nisamudheen15-Apr-07 18:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.