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
2 answers
70 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 ...
user avatar
  • 185
-2 votes
3 answers
205 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 ...
user avatar
  • 6,711
0 votes
0 answers
93 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 ...
user avatar
-3 votes
3 answers
58 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 ...
user avatar
0 votes
1 answer
522 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 ...
user avatar
-3 votes
2 answers
220 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
2 votes
3 answers
629 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 ...
user avatar
  • 1,401
0 votes
2 answers
152 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 ...
user avatar
-1 votes
2 answers
319 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 ...
user avatar
0 votes
2 answers
358 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: ...
user avatar
  • 369
2 votes
2 answers
2k 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 ...
user avatar
0 votes
1 answer
76 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'...
user avatar
5 votes
2 answers
555 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 ...
user avatar
  • 155
-2 votes
2 answers
55 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 ...
user avatar
  • 1,555
0 votes
2 answers
42 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 ...
user avatar
  • 109
2 votes
3 answers
463 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 = ...
user avatar
  • 211
-2 votes
2 answers
129 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?
user avatar
  • 267
1 vote
2 answers
2k 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 ...
user avatar
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 ...
user avatar
  • 1,045
0 votes
0 answers
51 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 ...
user avatar
1 vote
5 answers
236 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:...
user avatar
1 vote
4 answers
264 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 ...
user avatar
1 vote
2 answers
76 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 ...
user avatar
  • 405
5 votes
1 answer
154 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'...
user avatar
1 vote
0 answers
61 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 ...
user avatar
  • 197
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 ...
user avatar
3 votes
4 answers
2k 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 ...
user avatar
-3 votes
1 answer
146 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 } ...
user avatar
2 votes
1 answer
134 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 ...
user avatar
1 vote
3 answers
99 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 ...
user avatar
4 votes
3 answers
314 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 ...
user avatar
6 votes
1 answer
3k 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 ...
user avatar
  • 329
4 votes
5 answers
222 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 ...
user avatar
1 vote
1 answer
97 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 ...
user avatar
4 votes
1 answer
4k 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 ...
user avatar
  • 59
1 vote
1 answer
426 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 ...
user avatar
8 votes
1 answer
4k 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 ...
user avatar
93 votes
12 answers
33k 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 ...
user avatar
  • 1,081
1 vote
2 answers
74 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 ...
user avatar
  • 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 ...
user avatar
0 votes
1 answer
92 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)...
user avatar
2 votes
0 answers
136 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) {...
user avatar
  • 289
2 votes
2 answers
524 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: ...
user avatar
0 votes
0 answers
54 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....
user avatar
3 votes
4 answers
890 views

Alternative to nested-if on single return functions

I'd like to see if there has been any precedent on alternatives to nested-ifs--particularly for error-code returns. My workplace requires one return per function, so I cannot early exit. Here is some ...
user avatar
  • 41
1 vote
5 answers
350 views

When do I stop being paranoid about my code failing? [closed]

I'm currently designing a system that, no matter how hard I try to break, slow network, failures, random server deaths, it can recover and it can re-build again. Each action it does is a fragment and ...
user avatar
0 votes
0 answers
57 views

Streaming Promises in NodeJS

Imagine a typical HTTP service that does async db queries. If HTTP requests are received more quickly than the db can complete queries (such as because the db disk or network is slow), the Promises ...
user avatar
  • 181
1 vote
2 answers
226 views

Error Codes with Properties Files or Database

I'm about to implement Error codes for my company API, so, based on rfc7807 I will include a type which is an error type which is basically an error category, and inside those categories we have a ...
user avatar
  • 19
3 votes
3 answers
2k views

Node.js error handling through each layer

I am looking for a way to handle errors in a Node.js application without getting lots of log entries for the same error event, one from each each affected layer. This might actually apply to any ...
user avatar
0 votes
1 answer
104 views

Sensible way to report errors from cron jobs

I have several jobs that run nightly. Generally they work but from time to time they fail. What's the best way for them to report failure? The way that seems obvious to me is to send email. I have ...
user avatar
  • 101

1
2 3 4 5 6