Skip to main content

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
8 answers
791 views

Fail fast is brittle

I am creating a CSV consumer (with Java). There is one field / column that should contain one of the values "Rename" or "Move". I implemented this by allowing mixed case of letters,...
NimChimpsky's user avatar
  • 4,670
29 votes
14 answers
10k views

Avoiding throw because we are not sure the exceptions will always be caught

I'm a junior in my company, and one of the coding rules they have is: "a constructor object must never fail" (i.e., never throw). So what if I give them an invalid parameter? Then, the ...
sayanel's user avatar
  • 399
-3 votes
2 answers
375 views

Is throwing an error in programming is good Idea at all? [duplicate]

I am wondering if throwing an error in programming is good Idea at all ? While programming we throw error when something unexpected or invalid has occurred. But if we have thrown exception and it is ...
FaisalAhmed's user avatar
0 votes
1 answer
139 views

Error codes in a legacy C++ project [closed]

Background I have a large C++ project which uses system error codes from errno.h, in C style. int Cls::foo(A arg, O* out) { if (!validate(arg)) return -EINVAL; if (!out) return -EINVAL; return 0;...
Abyx's user avatar
  • 1,455
1 vote
2 answers
77 views

CQRS how to display failed commands in the GUI

I am trying to use CQRS in my project and I was thinking how the GUI gets notified about failures in the GUI, when commands are fire and forget. My commandhandlers are not returning anything, but ...
hadamard's user avatar
  • 140
2 votes
4 answers
280 views

Watchdog/recovery mechanism for realtime embedded system (using heartbeat, exceptions and Posix signals)?

We have a large(ish) real-time embedded system. It's VxWorks, if that makes any difference. It has some C code in DKMs, but is 95%+ in C++. It has absolutely no exception handling, nor Posix signal ...
Mawg's user avatar
  • 4,226
5 votes
2 answers
2k views

C#: Refactoring an oversized try/catch/finally

Recently I've come to discover that I've inherited one of the internal auxilliary programs used. I've made a few minor fixes and features to improve it in the past, but now I've been given a major ...
rdi_pck's user avatar
  • 61
0 votes
2 answers
83 views

Deserializing serial protocol enums: Recoverable or unrecoverable errors?

I am currently implementing a library in Rust that implements a proprietary serial protocol. The protocol specifies several enum values, that mostly are returned by the hardware as u8s (bytes), but ...
Richard Neumann's user avatar
0 votes
1 answer
77 views

Communicating unpredicted Failure from Repository implementation to Applicaiton Layer

My application follows Clean Architecture wherein the Application Layer wraps the Domain Layer. I try to adhere to DDD more-so as a "guiding light" than a strict rulebook. Within the Domain ...
John Hall's user avatar
  • 163
1 vote
2 answers
189 views

Choosing a strategy for representing and handling errors (or more generally status codes) in java 8

I asked this questions on StackOverflow but it's definitely a bit too broad. Even for this website, although the question is about software design, it might not be enough "focused". I am ...
lux_piromani's user avatar
3 votes
2 answers
1k views

Standard error codes vs custom error codes in C

I am working on improving the code quality and portability of my C library, specifically a ring buffer implementation, that will be used in larger applications. I have encountered a dilemma regarding ...
Usman Mehmood's user avatar
0 votes
1 answer
372 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, ...
Hazzinator's user avatar
0 votes
1 answer
376 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 ...
Spenhouet's user avatar
  • 109
0 votes
1 answer
171 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, ...
Milkncookiez's user avatar
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 ...
Anatoly's user avatar
  • 264
1 vote
3 answers
597 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 (...
einpoklum's user avatar
  • 2,572
0 votes
2 answers
114 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 ...
Andy Lin's user avatar
  • 185
-2 votes
3 answers
224 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 ...
Vorac's user avatar
  • 7,129
0 votes
0 answers
301 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 ...
Burak Yilmaz's user avatar
-3 votes
3 answers
76 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 ...
hurryman2212's user avatar
2 votes
1 answer
7k 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 ...
William Rosenbloom's user avatar
-2 votes
2 answers
286 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
4k 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 ...
Konrad's user avatar
  • 1,559
0 votes
2 answers
158 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 ...
germanshedder's user avatar
-1 votes
2 answers
4k 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 ...
Taco's user avatar
  • 1,165
0 votes
2 answers
1k 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: ...
Tlaloc-ES's user avatar
  • 387
13 votes
3 answers
11k 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 ...
user3728501's user avatar
0 votes
1 answer
86 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'...
Alexis Wilke's user avatar
7 votes
2 answers
2k 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 ...
Izzo's user avatar
  • 205
-1 votes
2 answers
425 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 ...
WoJ's user avatar
  • 1,593
0 votes
2 answers
50 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 ...
Asker's user avatar
  • 109
2 votes
3 answers
2k 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 = ...
DT1's user avatar
  • 209
-2 votes
2 answers
145 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?
Stav Alfi's user avatar
  • 297
2 votes
2 answers
8k 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 ...
user2190492's 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 ...
samfrances's user avatar
  • 1,085
0 votes
0 answers
433 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 ...
Guswiri Salpia's user avatar
1 vote
5 answers
2k 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:...
jaskij's user avatar
  • 575
1 vote
4 answers
951 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 ...
Vincent Miller's user avatar
1 vote
2 answers
211 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 ...
Magnus's user avatar
  • 415
5 votes
1 answer
174 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'...
dani.luis's user avatar
1 vote
0 answers
102 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 ...
jjw's user avatar
  • 217
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 ...
user379490's user avatar
5 votes
4 answers
5k 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 ...
CoderGuy's user avatar
  • 169
-3 votes
1 answer
255 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 } ...
ChocolateOverflow's user avatar
2 votes
1 answer
295 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 ...
Youssef Sbeity's user avatar
1 vote
3 answers
245 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 ...
Roger Heathcote's user avatar
4 votes
3 answers
1k 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 ...
AndyM's user avatar
  • 309
7 votes
1 answer
7k 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 ...
Vencovsky's user avatar
  • 371
4 votes
5 answers
260 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 ...
Ganea Dan Andrei's user avatar
1 vote
1 answer
103 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 ...
The Dreams Wind's user avatar

1
2 3 4 5
7