Click here to Skip to main content
15,905,316 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)


 
GeneralEnum for non-critical error Pin
Jcmorin19-Apr-07 4:18
Jcmorin19-Apr-07 4:18 
JokeTell the user... Pin
Jeremy Falcon19-Apr-07 0:08
professionalJeremy Falcon19-Apr-07 0:08 
GeneralRe: Tell the user... Pin
Paul Conrad22-Apr-07 10:08
professionalPaul Conrad22-Apr-07 10:08 
GeneralThe fifth option is doing well!! Pin
Nibu babu thomas18-Apr-07 2:37
Nibu babu thomas18-Apr-07 2:37 
Cover up the mess and don't say anything

As of now it's 9.7 and 4.18 and this shows how unexpected stuffs are handled by some developers. And it has even beaten first option.

Q1. For non-critical errors:
 
Set a global error flag                    13  2.47  
Return a reserved value                    161 30.61  
Return an encoded error value (eg HRESULT) 88  16.73  
Throw an exception                         211 40.11  
<code>Cover up the mess and don't say anything   51  9.7  </code>
Total                                      526 100%  


Q2. For critical errors <code>that leave the app in an undefined state</code>
 
Set a global error flag                    19  3.61  
Return a reserved value (0 or -1 etc)      40  7.6  
Return an encoded error value (eg HRESULT) 38  7.22  
Throw an exception                         401 76.24  
<code>Cover up the mess and don't say anything   22  4.18 </code> 
Total                                      526 100%  
Look at the second question, it says it leaves the app in an undefined state but 22 have voted for covering up!

It will be interesting to see how they cover up. One of the cover up mechanisms that I have seen is...

try
{
   // Something real bad
}
catch( ... )
{
   // This is bad.
   return false;
}



Nibu thomas
A Developer

Programming tips[^]  My site[^]

JokeAutomatic firing of responsible developer Pin
Ashley van Gerven17-Apr-07 0:51
Ashley van Gerven17-Apr-07 0:51 
GeneralYeaaaaaaassss ! Pin
Kochise17-Apr-07 2:00
Kochise17-Apr-07 2:00 
GeneralRe: Yeaaaaaaassss ! Pin
StevenWalsh18-Apr-07 3:13
StevenWalsh18-Apr-07 3:13 
GeneralRe: Automatic firing of responsible developer Pin
Corinna John18-Apr-07 7:37
Corinna John18-Apr-07 7:37 
GeneralRe: Automatic firing of responsible developer Pin
Kochise18-Apr-07 21:36
Kochise18-Apr-07 21:36 
GeneralRe: Automatic firing of responsible developer Pin
ThatsAlok20-Apr-07 20:58
ThatsAlok20-Apr-07 20:58 
GeneralAnnas blog and Likely{T} Pin
peterchen16-Apr-07 23:46
peterchen16-Apr-07 23:46 
GeneralRe: Annas blog and Likely{T} Pin
Andre xxxxxxx20-May-07 3:25
Andre xxxxxxx20-May-07 3:25 
GeneralClaim it's Windows' fault ! Pin
Kochise16-Apr-07 21:52
Kochise16-Apr-07 21:52 
GeneralTry and Recover, Otherwise Die and Leave a Suicide Note Pin
Ri Qen-Sin16-Apr-07 8:33
Ri Qen-Sin16-Apr-07 8:33 
GeneralRe: Try and Recover, Otherwise Die and Leave a Suicide Note Pin
Almighty Bob16-Apr-07 11:43
Almighty Bob16-Apr-07 11:43 
GeneralCString Pin
bob1697216-Apr-07 5:27
bob1697216-Apr-07 5:27 
GeneralRe: CString Pin
Nemanja Trifunovic17-Apr-07 9:04
Nemanja Trifunovic17-Apr-07 9:04 
GeneralRe: CString Pin
bob1697217-Apr-07 10:26
bob1697217-Apr-07 10:26 
GeneralRe: CString Pin
StevenWalsh18-Apr-07 3:16
StevenWalsh18-Apr-07 3:16 
GeneralRe: CString Pin
ThatsAlok20-Apr-07 21:00
ThatsAlok20-Apr-07 21:00 
GeneralExceptions are good Pin
Gary Wheeler16-Apr-07 2:33
Gary Wheeler16-Apr-07 2:33 
GeneralRe: Exceptions are good Pin
bob1697216-Apr-07 5:22
bob1697216-Apr-07 5:22 
General...unless you are using C++ Pin
peterchen16-Apr-07 10:21
peterchen16-Apr-07 10:21 
GeneralRe: ...unless you are using C++ Pin
Nemanja Trifunovic16-Apr-07 13:34
Nemanja Trifunovic16-Apr-07 13:34 
GeneralRe: ...unless you are using C++ Pin
peterchen16-Apr-07 21:45
peterchen16-Apr-07 21:45 

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.