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.
308 questions
2
votes
3
answers
183
views
API Design: Should I explicitly check for and throw on nullptr parameters if I have full control?
Say I have the following header
#ifndef WINDOW_HPP
#define WINDOW_HPP
// includes...
namespace window
{
struct Window
{
GLFWwindow *handle = nullptr;
};
struct ...
29
votes
14
answers
11k
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 ...
0
votes
1
answer
172
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;...
2
votes
4
answers
494
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 ...
0
votes
2
answers
107
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 ...
1
vote
2
answers
281
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 ...
0
votes
1
answer
594
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
217
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, ...
1
vote
3
answers
965
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
votes
3
answers
235
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 ...
-3
votes
3
answers
100
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 ...
-2
votes
2
answers
325
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 ...
0
votes
2
answers
173
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 ...
0
votes
2
answers
2k
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:
...
0
votes
1
answer
103
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'...
-1
votes
2
answers
748
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 ...
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 = ...
3
votes
2
answers
9k
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 ...
0
votes
0
answers
661
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
4
answers
1k
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 ...
5
votes
1
answer
189
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'...
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 ...
-3
votes
1
answer
287
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
} ...
1
vote
3
answers
286
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 ...
7
votes
1
answer
8k
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 ...