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 ...
1
vote
1answer
102 views
What are the limitations of Java exception approach to errors?
Please ignore performance issues, I am interesting in data flow, safety, modelling, reasoning.
I wonder what are the limitations of exception approach to error reporting implemented like in Java ...
0
votes
3answers
64 views
Preventing information leakage while returning an error message
Say my website contains 2 functions:
Allow a user to change their own password
Allow an administrator to change a user's password (the user must change again before they login)
Now let's say that ...
10
votes
5answers
282 views
Is indiscriminately catching exceptions (Pokemon exception handling) ever acceptable? [duplicate]
Normally, I don't anticipate exceptions and if I get them, its something that I can't fix in my code - bad user input or connectivity issues with the database.
But errors do occur so at the very ...
0
votes
0answers
21 views
Handling error with Promise
I'm writing a small application in TypeScript that has to do some asynchronous operation and I'm doing it with Promise and async/await sugar. But my problem do not rely on the particular language or ...
7
votes
2answers
123 views
How to work with/around an API that does not return errors?
I am currently working on a project which requires data fetching from a 3rd party closed API (over SOAP).
Currently I'm in a situation where I have to do argument and data validation inside our ...
1
vote
1answer
83 views
Standalone library for error logging?
Background
Here is how I currently log any exceptions that occur in my code:
Pass each object instance the path to a file where I want all of the logging to happen.
Each of the objects have their ...
2
votes
1answer
25 views
Handling and reporting errors consistently
Errors can come from many different sources - third-party services, libraries, environment, etc. When an error prevents a user from performing their desired action, these diverse errors should be ...
2
votes
2answers
85 views
Java EE exceptions for validation and APMs
In my current work, we have some Java EE applications and we use exceptions and exception mappers to deal with user errors, i.e. that can't be dealt with in the frontend.
We usually reply with a 400, ...
1
vote
1answer
63 views
Error handlers inside Promise.all
I'm looking at this piece of code and whilst it works, it feels wrong to me. I'm wondering if I am looking at an anti-pattern?
The code starts with two promises, getAccounts and getTransactions. On ...
4
votes
1answer
106 views
Overflow Exception Checking Problem
Background
I have to call a method that needs to return a signed integer (see code block below) after converting from an unsigned integer. The reason for this is that I have to do bit-wise math that ...
-2
votes
1answer
91 views
Investigating in a highly distributed environment [closed]
I was asked this by an interviewer today and unfortunately he wouldn't share the kind of answer he was looking for so I'm hoping maybe the community can help.
Say you're an engineer at company X and ...
53
votes
5answers
7k views
Will a computer attempt to divide by zero?
We all know 0/0 is Undefined and returns an error if I were to put it into a calculator, and if I were to create a program (in C at least) the OS would terminate it when I try to divide by zero.
But ...
35
votes
7answers
4k views
Arguments against error suppression
I've found a piece of code like this in one of our projects:
SomeClass QueryServer(string args)
{
try
{
return SomeClass.Parse(_server.Query(args));
}
...
1
vote
1answer
83 views
Recieving errors without engaging in excessive communication when using sockets
I'm currently writing a program that communicates with a server over TCP sockets. I originally planned for the communication to include a message confirming successful communication at the end of ...
2
votes
2answers
263 views
Error handling in C++
So, in the recent weeks I delved into C++ programming, and I programmed some things in SDL. Doing so, you always have to deal with a lot of (ugly) C++ code, which looks more like C than C++.
One thing ...
1
vote
2answers
96 views
Load to list in one loop and then process list in another or do it all at once
I have a dataset full of rows that I must initialize into myclass and then process.
I am currently looping through each row in the dataset, initializing a new instance of myclass, then adding that ...
0
votes
2answers
97 views
Should I log errors in the function they occur? or pass them back and log them when control returns?
One of the things I love about Go is how they encourage passing errors as return values, but when it comes to logging what is the most maintainable solution: passing the error as far back down the ...
2
votes
5answers
333 views
Handling null-references in C# logic
Let's say I have an API method with can be used to calculate the sum of all orders made by a specific customer:
Amount CalculateOrderSum(int customerId)
{
// Perform authentication to make sure ...
3
votes
3answers
164 views
Are exceptions only for handling errors?
I have a script that throws exceptions when something goes wrong. However, for the purposes of testing I also want to capture specific points although I'm not sure whether they would be deemed errors ...
26
votes
3answers
1k views
Should I use HTTP status codes to describe application level events
Several servers I have dealt with will return HTTP 200 for requests that the client ought to consider a failure, with something like 'success : false' in the body.
This does not seem like a proper ...
3
votes
1answer
28 views
How to design error monitoring for batch jobs with multiple and diverse steps?
I'm working on a software to integrate an e-commerce store and the company ERP. All the integration steps are run as a unique batch job, every 5 minutes. Things are working under production, but I'm ...
-3
votes
2answers
193 views
Why ever use exception throw (in C#) except for Class Library development? [duplicate]
Why would I ever throw exceptions in code? (except for one specific scenario where I am developing a class library which the consumers of it, will not want / be able to change).
To be more specific, ...
8
votes
2answers
416 views
Is the strong exception safety guarantee with a pass-by-value argument which can throw on destruction possible?
Suppose you have a type with a throwing destructor, and a function receiving it by value.
Can that operation ever provide anything better than the basic exception guarantee?
Or formulated differently, ...
52
votes
7answers
4k views
Should one check for every little error in C? [duplicate]
As a good programmer one should write robust codes that will handle every single outcome of his program. However, almost all functions from the C library will return 0 or -1 or NULL when there's an ...
4
votes
1answer
134 views
How to approach syntax errors when developing a lexical analyser?
I am writing an interpreted domain-specific language for my application. Each statement is parsed and executed as soon as lexical analyser decides that the end of statement is reached. It's handling ...
1
vote
1answer
145 views
How often should I use try/catch statements? [duplicate]
Everything I've read says that they should be used when something that simply "shouldn't happen" does happen. But the thing is, there's a lot of things that could go wrong.
For example, if I'm ...
3
votes
1answer
240 views
Best practice for angular service return value
I have a number of angular services (e.g. a user service) which make various HTTP calls and I'm wondering what the best practice would be for handling errors. For example, I could do:
function ...
0
votes
0answers
84 views
Test for PHP Errors using Browser Emulator (Mink)
I want to know the most robust way of checking for PHP error messages when running automated tests that interact with a PHP application via a browser emulator.
The reason is: I use Behat, Mink and ...
0
votes
0answers
62 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
171 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
2k 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
92 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
116 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
42 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.)
8
votes
2answers
236 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
414 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
41 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
392 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
183 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
160 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
126 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 ...
6
votes
2answers
655 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 ...
5
votes
2answers
805 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
152 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
63 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
198 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
111 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
142 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
971 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
209 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 ...