Questions related to handling errors and exceptions. According to Wikipedia, Exception handling is the process of responding to the occurrence, during computation, of exceptions – anomalous or exceptional events requiring special processing – often changing the normal flow of program execution. It ...

learn more… | top users | synonyms

83
votes
10answers
9k views

The modern way to perform error handling…

I've been pondering this problem for a while now and find myself continually finding caveats and contradictions, so I'm hoping someone can produce a conclusion to the following: Favour exceptions ...
79
votes
12answers
6k views

How big does my project need to be for me to unit test it? [closed]

I assume that my project is decoupled enough to allow for unit testing. But how big, exactly, in terms of clases and functions does my project need to be to make unit testing worthwhile? We all make ...
59
votes
14answers
8k views

Why is 0 false?

This question may sound dumb, but why does 0 evaluates to false and any other [integer] value to true is most of programming languages? String comparison Since the question seems a little bit too ...
59
votes
14answers
8k views

Should one check for null if he does not expect null?

Last week, we had a heated argument about handling nulls in our application's service layer. The question is in the .NET context, but it will be the same in Java and many other technologies. The ...
54
votes
16answers
19k views

How to handle divide by zero in a language that doesn't support exceptions?

I'm in the middle of developing a new programming language to solve some business requirements, and this language is targeted at novice users. So there is no support for exception handling in the ...
54
votes
11answers
4k views

I've been told that Exceptions should only be used in exceptional cases. How do I know if my case is exceptional?

My specific case here is that the user can pass in a string into the application, the application parses it and assigns it to structured objects. Sometimes the user may type in something invalid. ...
39
votes
10answers
3k views

Why are exceptions considered better than explicit error testing? [duplicate]

Possible Duplicate: Defensive Programming vs Exception Handling? if/else statements or exceptions I often come across heated blog posts where the author uses the argument: "exceptions vs ...
39
votes
6answers
3k views

How safe are hidden AJAX requests that fake performance?

What is a hidden AJAX request? I've noticed an increase in the usage of hidden AJAX requests designed to make a user's action appear to happen immediately. I'll refer to this type of AJAX request as ...
39
votes
2answers
15k views

What are the definitive guidelines for custom Error Handling in ASP.NET MVC 3?

The process of doing custom error handling in ASP.NET MVC (3 in this case) seems to be incredibly neglected. I've read through the various questions and answers here, on the web, help pages for ...
33
votes
7answers
3k views

Should a stack trace be in the error message presented to the user?

I've got a bit of an argument at my workplace and I'm trying to figure out who is right, and what is the right thing to do. Context: an intranet web application that our customers use for accounting ...
32
votes
20answers
2k views

How do you tackle really bizarre errors that keep you puzzled for more than 10 hours? [closed]

You know them, those errors that make NO sense. Where it seems like a gremlin just jumped deep inside your chips and messed up something. Do you take a walk, write stuff, call an uncle? I need help!!
26
votes
4answers
1k views

How much information about an error should be shown to the user?

Applications can always throw errors. If such an error occurs, the user should be notified, because what he asked the application to do has not succeeded. However, how much information should the ...
21
votes
15answers
7k views

Arguments for or against using Try/Catch as logical operators

I just discovered some lovely code in our companies app that uses Try-Catch blocks as logical operators. Meaning, "do some code, if that throws this error, do this code, but if that throws this error ...
20
votes
5answers
1k views

Is possible to write too many asserts?

I am a big fan of writing assert checks in C++ code as a way to catch cases during development that cannot possibly happen but do happen because of logic bugs in my program. This is a good practice in ...
13
votes
5answers
10k views

try-catch in javascript… isn't it a good practice?

There is a provision for try-catch block in javascript. While in java or any other language it is mandatory to have error handling, I don't see anybody using them in javascript for greater extent. ...
12
votes
5answers
3k views

null pointers vs. Null Object Pattern

Attribution: This grew out of a related P.SE question My background is in C / C++, but I have worked a fair amount in Java and am currently coding C#. Because of my C background, checking passed and ...
10
votes
6answers
977 views

Designing database related methods, which is better to return: true/false or row affected?

I have some methods that perform some data changing in a database (insert, update, and delete). The ORM I'm using return row-affected int values for those type of method. What should I return for "my ...
10
votes
4answers
5k views

Handling Errors In PHP When Using MVC

I've been using Codeigniter a lot recently, but one thing that gets on my nerves is handling errors and displaying them to the user. I've never been good at handling errors without it getting messy. ...
10
votes
4answers
2k views

`trigger_error` vs `throw Exception` in the context of PHP's magic methods

I'm having a debate with a colleague over the correct usage (if any) of trigger_error in the context of magic methods. Firstly, I think that trigger_error should be avoided except for this one case. ...
9
votes
4answers
579 views

Recommend a design pattern/approach to exposing/tolerating/recovering from system errors, Exception handling (e.g.s in Java, C++, Perl, PHP)

Can you recommend a design pattern/approach to exposing/tolerating/recovering from system errors, Exception handling (Java, C++, Perl, PHP)? Some errors need to be reported. Some errors can be ...
8
votes
8answers
863 views

Using a try-finally (without catch) vs enum-state validation

I have been reading the advice on this question about how an exception should be dealt with as close to where it is raised as possible. My dilemma on the best practice is whether one should use a ...
8
votes
4answers
570 views

Is error suppressing bad practice?

On a SO question I asked here about some code I was unsure about, someone replied "BTW, horrible code there: it uses the error suppressing symbol (@) a lot." Is there a reason why this is bad ...
8
votes
3answers
1k views

Exceptions or Error codes

We are building a web service(SOAP, .Net) which would be talking to (mostly) native clients (windows, C++) and we are wondering what is the best way to communicate errors to the client (e.g. ...
8
votes
3answers
1k views

Different callbacks for error or error as first argument?

We (and the JS SO chat room) had a talk with @rlemon some days ago about his Little-XHR library about error handling. Basically, we wanted to decide which error handling pattern should be used: ...
7
votes
3answers
1k views

Page Not Found: 404 - the best content to put in this page [closed]

Do you let me know what kind of content I should put in the error-page like "404 page not found"? Example: "Unfortunately an error has occurred during the processing of your page request." "Page ...
6
votes
3answers
547 views

How to Implement Error Handling [closed]

Even though I've programmed on a professional level for some years I still do not fully understand error handling. Although my applications work fine, the error handling isn't implemented at a ...
6
votes
5answers
641 views

Checked vs Unchecked vs No Exception… A best practice of contrary beliefs

There are many requirements needed for a system to properly convey and handle exceptions. There are also many options for a language to choose from to implement the concept. Requirements for ...
5
votes
3answers
561 views

Authoritative sources for exception handling best practices [closed]

My work place suffers from a bad case of the Pokemon Exception Handling anti-pattern with constructs like the following splattered across the code base: try { ... } catch (Exception ex) { // ...
5
votes
2answers
235 views

Is error suppression acceptable in role of logic mechanism?

This came up in code review at work in context of PHP and @ operator. However I want to try keep this in more generic form, since few question about it I found on SO got bogged down in technical ...
5
votes
3answers
214 views

When you write wrappers for APIs how do you handle usage errors?

When you write wrappers for APIs how do you handle usage errors? Do you assume that the user uses it right and write the wrapper such that it makes the call to the server and let the server return ...
5
votes
3answers
518 views

How should a web API handle misspelled/extra parameters?

Question: For a public facing web API(send HTTP Get/Post requests, get JSON/XML data back), how should parameters be handled that are either misspelled or are extra. It seems to me that if the ...
4
votes
2answers
527 views

Is there a term for the error-handling anti-pattern of discarding all available info and just returning failure?

From time to time (unfortunately way too often) I have to fix code such as this: // C++ code bool anyOldFunction(Param p) { try { ... if(some_condition_here) { handleErrorX(); return ...
4
votes
4answers
964 views

Exceptions vs ErrorCodes when working with devices

Out team is at the cusp of a new project. One of the components at the boundary of the system is the component which interacts with a printer through an external COM component (referenced as a usual ...
4
votes
3answers
527 views

Best Practice: Should error messages be handled by the API or by the App?

I am designing an application that interacts with a RESTful API. When returning error messages like Unable to sign up user Should the error message be generated by the app? or by the API? I am ...
4
votes
3answers
379 views

How should my web application handle common errors such as incorrect password, session timeout, etc.?

How should my web application handle common errors such as incorrect password, session timeout, etc.? I have a class called Hotmail that contains various method such as login, logout etc. To ...
4
votes
1answer
158 views

Why is nesting or piggybacking errors within errors bad in general?

Why is nesting or piggybacking errors within errors bad in general? To me it seems bad intuitively, but I'm suspicious in that I cannot adequately articulate why it is bad. This may be because it is ...
3
votes
5answers
608 views

How should I handle exception that *should* never be thrown? [duplicate]

What is the best way to handle errors that shouldn't ever happen? My current way to do this is to throw an exception if the 'thing that shouldn't happen' does happen, like so: /* * Restoring from a ...
3
votes
1answer
96 views

Invalid data returned, which HttpCode to return?

My web application calls a third party API. If I successfully call the API but invalid data is returned which cannot be processed by my system what is the most appropriate HttpCode to return to the ...
3
votes
3answers
136 views

handling a GET error properly

I have a website that takes two primary get strings: ?type=GAME&id=SomeGameID ?type=SCENARIO&id=SomeScenarioID for reasons unknown, I have recently begun receiving requests for erroneous ...
3
votes
3answers
295 views

How can I ensure a method is called only once when using a API?

In general, if I am using an API whose methods have side-effects that I only want to occur once, how can I guarantee that my own application only calls them once even if an error occurs before it can ...
3
votes
3answers
167 views

When should I decline to make a requested change?

I work on the software side of a company that provides custom hardware with software running on top of it. Often times the hardware is not engineered well. In those cases, I am often asked first to ...
3
votes
6answers
789 views

Whats the best way to handle errors in code?

So I'm a little concerned about my error handling... Currently my execution path looks something like this: Users.aspx -> App_Code/User.cs -> Data Layer/User.cs So now when I try to update a ...
3
votes
2answers
69 views

What is better to return from the DataService: Status or Exceptions?

I have a MVVM app with DataServices (using mvvmlight). Right now, i'm using it like var answer = await myDataService.PullList(categoryId); if (answer.Status == Ok) ...
3
votes
2answers
195 views

Error checking in actor-based paradigm

I have an existing Scala application that I am trying to refactor in order to use Akka. One of the problems I have is how to manage error-checking in actor-based applications. Usually error-checking ...
3
votes
1answer
157 views

Returning status code where one of many errors could have occured

I'm developing a PHP login component which includes functions to manipulate the User object, such as $User->changePassword(string $old, string $new) What I need some advice with is how to return a ...
2
votes
1answer
319 views

What's the difference between robustness and fault-tolerance?

Systems / programs / distributed algorithms / ... are often described with the predicate robust or fault-tolerant. What is the difference? Details: When I google for +robust +"fault-tolerant", I ...
2
votes
2answers
102 views

How does one handle an incorrect resource file?

I'm starting the parser that will handle one of the key features of my app and realizing exactly who easy it would be for me to screw up a resource file that is provided to the application. For ...
2
votes
4answers
170 views

What is the best way to go about testing that we handle failures appropriately?

we're working on error handling in an application. We try to have fairly good automated test coverage. One big problem though is that we don't really know of a way to test some of our error handling. ...
2
votes
1answer
1k views

web server response code 500

I realize that this may spur a religious discussion, but I discussed this with friends and get great, but conflicting answers and the actual documentation is of little help. What does the 500 series ...
2
votes
4answers
638 views

Should I achieve validation by handling errors in classic ASP?

I came across this while modifying an old ASP application: ON ERROR RESUME NEXT ivalue = CDATE(ivalue) IF err.number > 0 THEN ivalue = CDATE(date) END IF err.clear This doesn't look like ...