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
-2
votes
2answers
45 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 ...
0
votes
2answers
39 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 ...
2
votes
3answers
361 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 = ...
-2
votes
2answers
123 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?
1
vote
2answers
385 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
9answers
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 ...
0
votes
0answers
44 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
5answers
165 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:...
1
vote
4answers
200 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
1answer
52 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 ...
4
votes
1answer
146 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
0answers
57 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 ...
55
votes
11answers
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 ...
3
votes
4answers
569 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 ...
-3
votes
1answer
121 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
1answer
83 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
3answers
89 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
3answers
199 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 ...
5
votes
1answer
2k 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 ...
3
votes
5answers
218 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
1answer
91 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
1answer
2k 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 ...
1
vote
1answer
271 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 ...
7
votes
1answer
3k 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 ...
77
votes
12answers
26k 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
vote
2answers
68 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 ...
0
votes
1answer
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
1answer
88 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
0answers
110 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) {...
2
votes
2answers
387 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
0answers
49 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....
3
votes
4answers
664 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 ...
1
vote
5answers
345 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 ...
0
votes
0answers
47 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 ...
1
vote
2answers
170 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 ...
2
votes
3answers
1k 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 ...
0
votes
1answer
55 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 ...
2
votes
2answers
108 views

How do I recover from failed writes?

I'm writing logic for a patchable game, and patching involves modifying multiple files. type UpdateInfo { file string data []byte at int64 } func AtomicUpdate(ui <-chan UpdateInfo) ...
4
votes
1answer
291 views

What's the benefit of avoiding partial functions in Haskell?

AFAIK in Haskell it is heavily recommended to avoid partial functions; and if these seem unavoidable (eg head) then return a Maybe. At least, so the Haskell wiki says 1 2 What's the use of the ...
-1
votes
3answers
227 views

When is it preferable to issue a warning to a user, rather than an error? [closed]

I am writing a semi-complex piece of scientific software. We offer our end users many configuration options for each job and allow users to specify configurations only partially, with reasonable/safe ...
3
votes
1answer
642 views

Managing error code and error message mapping

As part of a game engine I am writing in cython, one of the challenges I am facing is creating a consistent interface for error handling that works at the C and python levels of my code. I am ...
0
votes
1answer
111 views

How to handle errors that is caused by old data structure?

When a major data structure has been changed in an app, what is the best way to handle such kind of errors in the front-end side so that the app doesn’t break? For example, we have a list of users ...
1
vote
2answers
1k views

How to effectively handle 404/500 http errors in server-side rendering web application which uses store for state?

I'm working on a website using server-side rendering approach. I'm using React and Redux for this. Redux handles the state of the application and provides API to change the state. All asynchronous ...
0
votes
0answers
50 views

Patterns for handling a Multi Responsibility Response string

We have an off shore group that is responsible for a SOAP service. The service has a method that returns a key as a string, when everything goes correctly. When it doesn't the key is an error string. ...
2
votes
3answers
220 views

Dealing with API errors

I'm building a shop system which works in three parts: a mobile app (Android/iOS) which is used by customers to make orders, view products and so on, a desktop application, used by the managers to ...
0
votes
1answer
43 views

Handling different error types from diffierent libraries with express

Most of the express error handling documentation and tutorials I've read suggest using Express middleware to throw errors up to, and to handle the errors there. eg. From the Express documentation: ...
2
votes
3answers
276 views

Practical way to indicate an error from a function that returns a stuct instance?

Suppose I have a function that returns an instance of a struct with the following declaration: struct data API(void); Suppose also that there is a chance for the function to fail with an error ...
2
votes
2answers
315 views

A way not to forget to check for errors in C

As everybody knows, C allows us to write anything we want. There comes one big problem — we are the only who responsible to handle errors that comes from standard library functions and, therefore, ...
4
votes
1answer
235 views

How to get bug reports without inconveniencing the user

We have a piece of code that looks something like that: std::vector<int> computeGlobalResult() { auto globalResult = std::vector<int>{}; while (myCollection.size() < 100) ...
2
votes
2answers
171 views

How to create useful error messages in a JSON REST API without leaking implementation details across layers?

We're implementing a REST service with three main layers: Controller, Domain, Repository. The REST API is supposed to respond to error conditions with meaningful error messages. Suppose the general ...

1
2 3 4 5 6