Questions tagged [error-handling]

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 is provided by specialized programming language constructs or computer hardware mechanisms.

Filter by
Sorted by
Tagged with
0 votes
1 answer
55 views

HTTP error 404 or 500 from an internal call to a separate API?

I have an endpoint in API 1 (my api) that queries API 2 (another companies api) to view and edit objects stored in API 2's database. API 1 is essentially acting as a wrapper service around API 2, ...
0 votes
1 answer
130 views

How to E2E test handling of an unknown error in a client-server application?

Using a ton of libraries, IO, ... you cannot handle all imaginary errors. You will need some form of "catch uncaught exception" handling to still have a control flow for such a case. But if ...
  • 109
0 votes
0 answers
49 views

How to efficiently retry/reprocess errors on a multi-actions service?

I have a service responsible for processing orders from an e-commerce, within this service, there are several actions that need to be performed, some in order and some not. Example: Notify the user ...
0 votes
1 answer
79 views

Bubbling errors upstream in async message-based services

Imagine a simple set up of an API and a 2nd service, where the API pushes some msgs to the message queue and the service pulls them and processes them. Now, if an error occurs while processing a msg, ...
4 votes
3 answers
1k views

Error or not error?

I need to implement the following scenarios at the server: User sent too many answers in a given amount of time, for example, it can't submit more than 3 posts within an hour. User sent answer with ...
  • 258
1 vote
3 answers
475 views

Should I use the "die" idiom in C++?

If we implement the following function: template <typename... Ts> [[noreturn]] inline bool die(std::string_view message_format = "", Ts&&... args); We can then write: if (...
  • 2,489
0 votes
2 answers
82 views

How to tell client if predicate function fails?

Just say I have list APIs, and provide find() to search node. With this design if something went wrong during pre-conditions, client would have no idea about it because no status code provided. bool ...
  • 185
-2 votes
3 answers
221 views

How to signal a dealbreaker error from a c-tor?

Context: 128kB RAM, freeRTOS. Considered solutions: Exceptions. Discouraged by both the memory size and the code style guide. Late bool init(...);. Has worked for a decade but has it's problems - can ...
  • 7,015
0 votes
0 answers
146 views

microservice custom error messages

We use microservices and spring boot in our saas (multi tenant) projects. We will proceed through the schema per tenant. We manage the error messages we show to the users through a database. We are ...
-3 votes
3 answers
66 views

How to Validate Output Binary During/After Compilation on Platform without ECC Memory [closed]

On a platform with ECC memory, you can assure the compiled binary is 100% legit with EDAC daemon. (single-bit error will be corrected automatically, and multi-bit error will be logged so you can just ...
1 vote
1 answer
3k views

Websocket client reconnection best practices

I wasn't sure whether to post this on StackOverflow or here. Let me know if you think it belongs on StackOverflow. I have an application that will run semi-persistently, i.e. all the time. The ...
-3 votes
2 answers
233 views

Why does most software break or refuse to continue immediately if the folder where their data is stored is not available? [closed]

Most software creates a directory (usually in ~/Library or ~/Library/Application Support in MacOS) to store user preferences, browser history, etc. Most software attempts to create their data ...
user avatar
4 votes
3 answers
2k views

Business logic error handling. Should exceptions really be avoided?

C#'s primary error handling mechanism are exceptions and try pattern. We don't have access to discriminated unions yet like in case of F# and Rust Option<T> and Result<T, E> types. The ...
  • 1,489
0 votes
2 answers
153 views

How can I avoid re-running code when exceptions are thrown and user re-submits?

I have a checkout process that 1) creates a user account in Stripe and my database, 2) creates a paymentMethod in Stripe and logs the last4 in the database, 3) creates the subscription in Stripe and ...
-1 votes
2 answers
1k views

Determining the object that caused a null reference exception?

Frequently in applications we encounter situations that could throw a NullReferenceException; for example, assuming the following method's argument is a user defined reference type, accessing the ...
0 votes
2 answers
672 views

Is "error first" better than "if-else", why? [duplicate]

I have an eternal discussion in my work about why "error first" is "worng". In order to ensure what I try to tell with error first is the following code pattern: if condition: ...
  • 387
7 votes
2 answers
5k views

What are the best practices when implementing C++ error handling?

FYI: I was asked to post this on softwareengineering - this question was originally posted on stack overflow, but they are a bit funny about broad questions over there, hence I was told to post here ...
0 votes
1 answer
77 views

What is the current practice in handling connection errors when the service "offers" multiple IP addresses?

With the current implementation of getaddrinfo(), I'm not given any information about a timeout of the IP address(es) returned. The library implementing that function has the information, but I haven'...
5 votes
2 answers
1k views

Is there a standard error handling design pattern for C?

I'm working on a large C application that I've divided into sub-libraries (e.g. networking, message handling, message building, etc.) I've converged onto a pattern where functions are only allowed to ...
  • 175
-2 votes
2 answers
85 views

API: should a problem with data be announced by a HTTP code or in the response body?

After years of (amateur, dirty) personal API development I finally decided to follow some best practices. My problem: the API may have problems, say, retrieving some data. It will gracefully handle ...
  • 1,551
0 votes
2 answers
46 views

Should an Express error handler be used to send HTTP 4xx responses?

In other words, should the raising of an HTTP 4xx code be considered an error, and should the job of sending an HTTP 4xx code to a client be delegated to an error handler? Or is it simpler to just ...
  • 109
2 votes
3 answers
784 views

Error handling. Is it always necessary?

So, today I was reading a piece of code I found this function: Public Function FolderExists(sPath As String) As Boolean Dim FSO As New FileSystemObject On Error GoTo errHandler sPath = ...
  • 211
-2 votes
2 answers
136 views

Should servers exit with 0 or 1 in case of caught errors?

What is the best practice in case a service has an error which we caught and handled? Do we exit code 1 or 0?
  • 287
2 votes
2 answers
4k views

Error handling for repository: exceptions or wrapping return value?

The question is about a desktop application I'm creating in C# and WPF. As very common I'm using the repository pattern in my Data Access Layer for my CRUD operations. All data comes from the ...
31 votes
9 answers
10k views

"Dead programs tell no lies" in the context of GUI programs

In The Pragmatic Programmer, the authors write: One of the benefits of detecting problems as soon as you can is that you can crash earlier, and crashing is often the best thing you can do. The ...
  • 1,065
0 votes
0 answers
138 views

Best way to trigger javascript error to go to catch block

I have a couple of doubts regarding the quality of my code. I'm working on a helper function (for KoaJS) where I'm validating a Firebase ID token. If it is valid, I return the decoded token; otherwise ...
1 vote
5 answers
696 views

How to write retry code when failure is inidicated by throwing an error?

Assume I have an API that indicates failure by throwing an error (because errors are not expected). In this situation, how should retry code be written? My first thought was to use something like this:...
  • 575
1 vote
4 answers
552 views

Is having 3 return types for a function, in order to facilitate error handling a bad idea?

I have a function which returns either true/false, each return plays nicely with the function name: isOnline, however, there are cases in which I want to throw an error inside of it. Maybe the status ...
1 vote
2 answers
101 views

Best way to display errors from a model to the user?

I'm developing an app (using Flutter) that has a model that contains most of the business logic, and a view that displays the user interface. The model can call notifyListeners to inform the view that ...
  • 405
5 votes
1 answer
161 views

Clean way to handle different exceptions in Javascript?

I'm Java developer and I'm now learning Javascript creating a personal project. I don't know how to handle different errors in Javascript in a clean way and I can't find a good solution on the web. I'...
1 vote
0 answers
70 views

Is there a easy and useful error handling algorithm for bottom-up based parser?

My English skill is poor because I'm not a native English speaker. Please understand. I wonder that there is a error handling algorithm easy and useful in LR parser. LR Parser is bottom up based so it ...
  • 207
55 votes
11 answers
11k views

Is there a general solution to the problem of "sudden unexpected bursts of errors" in software?

Let me explain what I mean. I have made a complex, highly polished over years PHP framework/library for my own use. I very aggressively log the smallest notice and immediately deal with it as soon as ...
4 votes
4 answers
3k views

HTTP POST request status 200 vs 204 vs 404

Our POST API takes in an identifier (let's say deviceId) in order to compute the accuracy of the location we have stored for that device in a DB; the result of that compution is then saved in a ...
  • 159
-3 votes
1 answer
194 views

Is it good practice to use try/catch like Python in Java?

I mainly use Python and just started learning Java. For now, I've tried using try/catch for basic file read/write as follows public String[] readFile(String fileName){ try{ // read file } ...
2 votes
1 answer
181 views

Exception handling with adapter design pattern in JavaScript

I am using an opencv.js Web Assembly build in the browser. The build comes with a JavaScript interface to call the WASM functions but it does not provide any memory management. For example every time ...
1 vote
3 answers
120 views

Which of these model error handling strategies makes most sense?

I am building an API in expressjs and, currently, mongo/mongoose. I currently have some model methods that return true or false, some that return a value or false, and some that return a value or ...
4 votes
3 answers
515 views

What are the best practices for handling errors in multi-step actions between client and servers?

I have a website which uploads job postings to my API, there are multiple steps to doing this: Upload a logo image to file storage. Insert data about the job posting into a database. Process a ...
  • 301
6 votes
1 answer
4k views

How to handle errors from back-end in front-end and different languages?

I have a rest api and a reactjs front end, in some cases, the api will send an error to the front end and I need to display that error. My app will support multiple languages, so the error must be ...
  • 329
4 votes
5 answers
226 views

Dealing with unwanted usages of a function

I am writing a function that I would not like to get called given a certain context and am wondering how best to convey that to possible users of the function. Assume, for exemplification, I am ...
1 vote
1 answer
99 views

What is better way to track mistakes in error-prone part of a feature?

That is quite specific circumstances I've come across, and I somewhat struggle to find proper way how to approach this. I'm given a class written in swift-language, which has a control property, like ...
4 votes
1 answer
5k views

How to handle failed API calls in C#

I built my API service and now I want to consume the information from a WPF application. So far I created the class ApiHelper which initializes and provides the HttpClient used to call the API ...
  • 59
1 vote
1 answer
615 views

exit and error handling in golang

I am new to Golang and I've seen it is very common to check for errors all the time. I am trying to find a way to not have my code polluted with "if error { log... }" or "if error { exit }". What do ...
10 votes
1 answer
6k views

Error handling in Nest service layer

I would like to create a REST API with NestJs. But I want to add GraphQL as another top level layer later on. So for the start I have the basic layers controller, service and TypeORM repository. Let's ...
98 votes
12 answers
40k views

Result object vs throwing exceptions

When sending a request to another module and expecting a result, it seems to me there are two ways of dealing with the 'non-happy paths'. Throw an exception Return a result object that wraps ...
  • 1,129
1 vote
2 answers
76 views

When using data and domain models, where should validation take place? And how should errors be fed back to the user?

When using data and domain models, where does validation take place? Both or just For example: class UsersDB(): def create(self, user_data): # Create user here return ...
  • 51
0 votes
1 answer
26 views

How do I solve the portability of WP_Error?

I wrote a lot of code with the intention of it being usable not only in the WordPress space, but everywhere and because of that, I've been very, very against returning WP_Errors and resorted to only ...
0 votes
1 answer
99 views

Handling Failed Rollbacks

To give an arbitrary example, let's say that I'm storing two objects, Item and Box, in the same database. These objects have a one-to-one relationship. Item has the following properties: ID (string)...
2 votes
0 answers
158 views

c++ exceptions, should the caller add the context or provide it to the callee?

Here is a piece of code. Basically, I load some source files, all of them are compiled separately, and then I link all of them. LinkedObject loadObject(std::vector<std::string>& fileNames) {...
  • 289
2 votes
2 answers
633 views

Error handling in an event driven system

The context I have two components A & B, which communicate through events . Components B is responsible for long running background processes and it listens to the following event: ...
0 votes
0 answers
56 views

Recommendation for design for errorcodes handling

Suppose you are dealing with a situation where you need to handle lot of errorcodes from different server, what would be the design to apply? Suppose 400 is errorcode, sometimes errormessage can vary....

1
2 3 4 5 6