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

0
votes
0answers
45 views

Checking for null pointers or allowing a math library to segfault?

I've been going through the GNU GSL design document and came across this interesting line in the Test suites section: N.B. Don't bother to test for null pointers -- it's sufficient for the library ...
4
votes
1answer
58 views

Should a web service return an error message if it receives unknown parameters?

I have a web service which allows to retrieve users: http://example.com/users. It returns a list of users. That service accepts a number of parameters (age, gender) to select which users to retrieve. ...
4
votes
5answers
696 views

Checking array size in C/C++ to avoid segmentation faults

So it's well known that C does not have any array bounds checking when accessing memory. Nowadays, if you call myArray[7] when you initialised it as int myArray[3], your program will get a segfault ...
1
vote
1answer
65 views

Should I put stack trace in error files and halt my app with user friendly error [closed]

In my earlier project I wrote an app that is used in-house. My usual practice is to capture errors/exceptions from different classes and threads and put them in different log files corresponding to ...
3
votes
3answers
93 views

Is this a valid situation for returning rather than throwing an exception?

This is not something I would ever normally do, but I have a situation where some existing legacy code is being reused in a new application. The code is shared and needs to be used by both the legacy ...
0
votes
1answer
30 views

Error handling in math library functions

When writing a library function, such as double getAvg(double[]); how should one handle the empty array? (Note that, mathematically speaking the avg of an empty set is undefined.)
7
votes
1answer
164 views

Do we need to validate entire module usage or just arguments of public methods?

I've heard that it is recommended to validate arguments of public methods: Should one check for null if he does not expect null? Should a method validate its parameters? MSDN - CA1062: Validate ...
4
votes
2answers
212 views

Rust-style error handling in C++

I've been reading some articles on how Rust does error handling using the Result<T, E> type and to me it seems like a hybrid best-of-both-worlds (exceptions and return codes) solution which can ...
2
votes
1answer
31 views

Storing exception information as a member variable for query later, bad practice? [duplicate]

I looking at the best way to handle exceptions, the answer to this question may be to handle the exception in a different place or to not handle to exception at all but to control the flow of the ...
2
votes
4answers
194 views

Design Pattern for retry and error handling

I'm trying to find a good design pattern, or perhaps series of patterns, for injecting error handling and retry handling when getting data from a webservice. For instance, I have: do { //get the ...
4
votes
2answers
89 views

Strategies to analyze collected exceptions

We want to add error feedback to our application. I had a look at existing solutions (e.g. raygun.io), but these work "in the cloud", which is a no-go for us: most installations of our application ...
1
vote
2answers
124 views

When writing a library or an API, when should and when shouldn't I validate or automatically correct errors in data provided by another developer?

I have a fairly good understanding of when data validation should and shouldn't exist when it comes when writing an application that is only dealt with by an end-user, and all the different tiers of ...
0
votes
1answer
86 views

Code Inside Catch Block

This question is related to both of these questions - Efficient try / catch block usage? and Dealing with error in data - Idempotent approach. When I encounter a void while reading a GIS data file I ...
5
votes
2answers
308 views

Designing exception classes

I'm coding a small library and I'm having some trouble with designing the exception handling. I must say that I am (still) confused by this feature of the C++ language and I tried to read as much as ...
4
votes
1answer
314 views

Should I always return an error code from C functions?

I have the following code in many places in a large application: if (datastruct.data_ok && cur_time > datastruct.start_time && cur_time < datastruct.end_time) { ...
0
votes
2answers
77 views

Catch unusual exceptions on production code for web apps

Lets say I have a web app, and despite my best testing efforts, several of the many thousands of people who uses it will find some way to generate an exception. Sure, I have error handling code for my ...
0
votes
4answers
60 views

Testing generic errors

I've got a program that validates it's input, and then errors. So far for each kind of error I created a new derived class. But this was getting pretty unwieldy (the input is complex so there are ...
1
vote
3answers
150 views

Protect memory from a potentially seg faulting function call

How can one safely call a function that might segfault without corrupting the stack or the heap? These SO questions cover using signal handlers and setjmp.h to regain control. Coming back to life ...
2
votes
4answers
95 views

What an application should do when there is an error notifying the user of an error?

Say I have an application, and it writes (among other things) errors to a log file. It's the first place the user would be asked to go and look if there was a problem. Let's also assume that this is a ...
1
vote
2answers
116 views

Why is there “Unknown error” in real life? [duplicate]

As a programmer, I always try my best to explain what happened in the code when I have to show an error message, for example: try { int a = b / 0; } catch (NumberFormatException ex) { ...
1
vote
2answers
625 views

How should I provide detailed information about an error, if not through HTTP status codes?

This question comes from here. I believe it deserves to be on its own instead of being lost in a long question with multiple points. I'm building an API and find myself limited by HTTP error ...
0
votes
1answer
112 views

How to handle coding errors in my PHP AJAX code?

How do I handle coding errors in my PHP which has no GUI, only an API? I am concerned that I might never know that there are any. Note that only I will develop the client side. This is not a public ...
7
votes
2answers
262 views

What's the best way to handle Windows API errors in response to system messages or when I have nowhere to return them to?

This is going to be a really stupid question and I hope it's fine for Stack Exchange at all, let alone just this part of it... Right now, my custom Table control uses panic() functions that print an ...
0
votes
1answer
71 views

Dealing with error in data - Idempotent approach

A prior question had an answer that interested me from a design perspective. I work in geospatial data and occasionally have to deal with voids when I read these binary files into my product. What is ...
32
votes
3answers
5k views

Is address 0000000C a special address?

When programming sometimes things break. You made a mistake and your program tries to read from a wrong address. One thing that stands out to me that often those exceptions are like : Access ...
2
votes
2answers
145 views

How to implement error handling/returning while streaming a message

Say someone calls a web service on a server, the relevant data is being retrieved in batches and the message is being streamed to the client. In the middle of the message some kind of exception is ...
-2
votes
3answers
180 views

Could programming ever have existed without error checking? [closed]

I think that in programming error checking is extremely important, not a secondary topic, what if your programme crashes without an error, just silently aborting? What if you must discover a ...
1
vote
2answers
161 views

Recovering a process after illegal instruction exception

Is it possible in theory to recover after a process is mistakenly pointed-out to read from a wrong memory address, rather than terminating it? Let say an error while working with registers lead the ...
1
vote
3answers
135 views

Coerce bad input or always crash early

The general consensus seems to favor the Crash Early approach, the most reputable source being the acclaimed Pragmatic Programmer book. And while I understand and agree with the advice in many ...
8
votes
2answers
649 views

How should I handle logger failures?

In several of our company's applications, we use a custom logger. It's fairly robust, though we may replace it with something like NLog in the future. One of the logger's tasks is to log any ...
2
votes
2answers
114 views

Preferred way of handling errors when loading an object from a file

If I want to load an object from a file, there are a number of things that can go wrong. Thus, one needs a way of handling errors when doing so. In some languages, like haskell, one can return a Maybe ...
0
votes
0answers
43 views

When calculating cyclomatic complexity, should Exception Handling considered? [duplicate]

When calculating the cyclomatic complexity of a piece of code (/method/program), should any Exception Handling be taken into account? For example, if you include a try-catch block in your ...
3
votes
1answer
554 views

MVC: Where is the right place to set error messages?

I have a ASP.NET MVC application where in all my Models have an Errors Property used to store non-validation errors which I than display in my Views. Where is the right place to populate the error ...
28
votes
7answers
1k views

Is it okay to use exceptions as tools to “catch” errors early?

I use exceptions to catch problems early. For example: public int getAverageAge(Person p1, Person p2){ if(p1 == null || p2 == null) throw new IllegalArgumentException("One or more of ...
4
votes
2answers
186 views

Defining error codes

We are designing an error-handling framework for a cryptographic library written in C. The approach we are taking is that relatively few errors are propagated back to the user since on most occasions ...
3
votes
0answers
181 views

Handling and managing error codes

I'm looking for examples of creating, handling and managing error numbers/codes. To understand what I'm takling about, let's take example scenario: (EU - end user, IT - it helpdesk) EU: - (calls IT) ...
4
votes
1answer
250 views

Error Handling Strategies in Multithreaded Environments

TL;DR What error generating and handling strategies do you use in Multithreaded code intended for use by others and why do you use them? If applicable, state what programming paradigm it's useful for. ...
-4
votes
1answer
125 views

Try and catch error trapping, why is it so significant? [duplicate]

I try to understand why should I "try" a method to catch errors. It looks to me like the concept is: "letting a process run assuming its not properly developed". Should I always assume that a ...
1
vote
2answers
230 views

Is goto to improve DRY-ness OK? [duplicate]

My code has many checks to detect errors in various cases (many conditions would result in the same error), inside a function returning an error struct. Instead of looking like this: err_struct ...
15
votes
2answers
495 views

Cleanest way to report errors in Haskell

I'm working on learning Haskell, and I've come across three different ways of dealing with errors in functions I write: I can simply write error "Some error message.", which throws an exception. I ...
10
votes
6answers
1k 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 ...
3
votes
2answers
1k views

IllegalStateException vs. IllegalArgumentException

In have written a function which expects the caller to pass in a configuration file like XML. Then I parse this given file and extract something which i then return. In this function (at least) two ...
30
votes
4answers
2k 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 ...
2
votes
0answers
115 views

Is there a theory for “transactional” sequences of failing and no-fail actions?

My question is about writing transaction-like functions that execute sequences of actions, some of which may fail. It is related to the general C++ principle "destructors can't throw," no-fail ...
1
vote
2answers
365 views

global try-catch in presentation layer

I have a 3-layered app structured as follows. Presentation Layer (ASP.NET MVC project) Business Logic Layer (Services for controllers in PL) Data Access Layer (Repositories) Each Controller in PL ...
3
votes
2answers
294 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) ...
2
votes
1answer
100 views

How to handle errors best addressed in a higher abstraction layer and dependent on state inferred in current layer?

I have a use-case that can be repaired, but the logic for repairing it is best done in a higher level of abstraction. Just throwing exception/failure is ugly because it's hard to pass back up through ...
2
votes
1answer
815 views

Passing multiple errors back from service layer

I am using Spring for a web application. To validate a user's input in a form such as for creating a Person entity I user JSR 303 validation to check for not null/empty or valid patterns etc.. Some ...
3
votes
6answers
2k 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 ...
0
votes
2answers
59 views

Handling ignorable failure conditions in a method

I'm working on a coarse API for performing higher level business functions. Under many conditions these functions may fail in a way that is expected (not exceptional), ie. the function may not be ...