Questions tagged [error-handling]

The various techniques used for maintaining stable program state in circumstances that, if not taken care of ("handled"), could cause serious issues, including logical bugs and abrupt execution termination.

Filter by
Sorted by
Tagged with
2 votes
1 answer
36 views

error tracking in api endpoint

I have built a simple Nuxt 3 app and have some custom api endpoints. I am currently tracking the user query and response statuses to have some insight when something goes wrong and that the app is ...
3 votes
1 answer
63 views

Take in 10 numbers, validate each input, append then in a list and then prints the sum of the list values

I'm practicing loops in Python and started trying to have a better approach with user inputs, is there better ways of dealing with inputs when coding? And I tried using deques too, it worked very well,...
1 vote
1 answer
52 views

Processing charge current error messages with HashMap<>

I have certain error states that I am displaying in my Android TextView but only one message is displayed at a time and if all values are set to 0, no message is displayed. So, I check all the values ...
1 vote
0 answers
49 views

Error handling for Laravel REST API client and server using bearer token authentication

I would like to query a REST API (which uses Bearer token authentication), handling several exceptions that might occur. Could you tell me if the following code (which I explain later in this post) is ...
0 votes
1 answer
60 views

Google App Script Automation for User Onboarding

Background I am a relatively new developer(> 2 years coding) working as an intern for a smaller company, as part of a now 4 person team. We had two other team members, one our system admin and the ...
0 votes
0 answers
27 views

Java utility which forwards a request to an error handler mapping

I have a class ErrorForward which is basically a utility. It's used in Servlets, inside the catch block. It forwards request to <...
1 vote
1 answer
47 views

Unit tests for PNGme steganography exercise in Rust

I want to become proficient in Rust and I've followed the PNGme exercise. I've completed it up until Chapter 4 included, where I've written a lot of tests myself for verifying that the command line ...
  • 111
2 votes
1 answer
78 views

Program to check if a window is opened or not during some time interval

I'm trying to write a program that will check if a window is opened or not, during a given time. I was able to do that, but now I'm trying to make my code look cleaner. I don't like how I implement ...
0 votes
2 answers
43 views

Trying to assign property until the setter stops throwing the exception

Can I improve this code and make it more beautiful? For example, for expressions in ReadConsole method is ugly for me. ...
's user avatar
2 votes
0 answers
58 views

JavaScript proxy for better stack traces from external libraries

I've been using the excellent pg-promise library for a few years now, but my primary irk with it is that the stack traces are sometimes unhelpful. For example, the following test will fail (currently ...
  • 133
1 vote
1 answer
46 views

Typescript error handler

I wrote a function in Typescript which takes required parameters, optional parameters and parameters with default value. I want to use this function for error handling of http requests. I am not sure, ...
3 votes
2 answers
130 views

Retry read/write until all bytes are transferred or error occurs

Currently I have a wrapper function for the read/write system calls, the purpose of which is to eliminate partial transfer ...
's user avatar
1 vote
1 answer
96 views

Open, read/write, then close a relative path

These functions will open a relative path, read or write to the file, then close. The purpose of these functions is to avoid duplicate code patters for accessing different files that only require one ...
's user avatar
6 votes
3 answers
672 views

Custom string-to-int converter

I have written the following function: ...
1 vote
1 answer
147 views

Try-catch-finally with 'using' in ADO.NET

I want to check if I'm correctly disposing of resources using Ado.NET. I'm not sure when the 'using' statement makes .Dispose() irrelevant. Please bear in mind I'm aware I shouldn't hardcode my SQL ...
3 votes
3 answers
108 views

Follow Up: Refactored C# Tool to Generate MS Word Document Mailbox List From MS Excel

Background Some very good observations were made about my original code in the 2 answers to this question. In this version I have attempted to reduce cyclic complexity and class coupling even more as ...
  • 19.5k
11 votes
7 answers
2k views

How much error handling is too much?

I have the following C# code (.NET 6): ...
  • 808
3 votes
1 answer
115 views

Dictionary based non-local mean implementation in C++

This is a follow-up question for Manhattan distance calculation between two images in C++ and Dictionary based non-local mean implementation in Matlab. For learning C++20 and researching purposes, I ...
  • 3,596
6 votes
1 answer
517 views

Implementation of exponential backoff algorithm

You can read about the algorithm here. An exponential backoff algorithm retries requests exponentially, increasing the waiting time between retries up to a maximum backoff time. An example is: Make ...
  • 370
-2 votes
1 answer
62 views

Check nullability vs throw NullExceptions [closed]

I have been trying to understand the difference between two approaches and have always got confused so thought of asking this question here. Consider following code, ...
5 votes
1 answer
93 views

Find the mean magnitude of values inside unit circle

I'm fairly new to Python and am exploring how to fix functions and make code 'more effective and readable'. As a first step, I would want to try to make shorter snippets of code here - for example by ...
  • 51
0 votes
0 answers
44 views

Create trigger that updates Table3 from an insert into Table1 that multiplied by a value in Table 2 in MySQL

I know this is probably more complicated than it needs to be, however, I would really appreciate some help. I'm trying to create a trigger in MySQL that will update the value in the Costs table when a ...
0 votes
1 answer
65 views

Use an exception to check if item in dictionary [closed]

I am using a KeyNotFoundException to check if an item exists in a Dictionary, creating it when the exception is thrown: ...
-1 votes
1 answer
252 views

Nested try-except for raising exceptions in Python

I'm wondering if the nested "try/except/else" structure (in the main function) is a good practice in Python. Right now, the structure is not that deep but I could continue on and on with ...
  • 133
1 vote
2 answers
85 views

Requiring query field to not be empty on search api

we have a RESTful API that includes an endpoint for search apiserver/v5/search?q=[search text] for any query, it passes it off to solr and returns the result like ...
7 votes
5 answers
2k views

Robust program to write an array of certain data type to a binary file and read back from it (C++17)

Problem description As the title indicates, I want to be able to write to and read from a binary file safely, in the sense that I want to have full control of everything that might go wrong. Since I ...
3 votes
1 answer
127 views

Class to wrap result or exception, similar to the OneOf approach

I recently came across the OneOf<T0,...,Tn> package from mcintyre321 via a video by Nick Chapsas, which presents the idea of holding exception types to be ...
  • 1,329
1 vote
1 answer
122 views

Calculate distances between two multi-dimensional arrays in Matlab

In question "Dictionary based non-local mean implementation in Matlab", the Manhattan distance between two three-dimensional structures can be calculated by ...
  • 3,596
4 votes
1 answer
231 views

Gear Shift Indicator using Hall Effect Sensors & 8x8 LED Display

I wired up a Gear Shift Indicator for my dad's car to display what gear it is currently in, and showing changes with animations (sliding up and down as appropriate, with a few bonus ones for fun at ...
1 vote
0 answers
50 views

Batch installing packages script in Octave

I am attempting to write a light script to deal with multiple package installation in Octave. The available packages can be checked in Octave Forge or wikipedia. For example, if the packages ...
  • 3,596
0 votes
1 answer
544 views

Spring boot: better way to handle response and exceptions

I am working on a quite a big Spring Boot web service and I wanted a standardized and simplified way to handle responses and exceptions by following fluent API design. So this is what I did and it ...
1 vote
0 answers
72 views

Dictionary based non-local mean implementation in Matlab

Given a dictionary including multiple X-Y pairs where X, Y are both three dimensional structure. dictionaryBasedNonlocalMean function return a ...
  • 3,596
7 votes
2 answers
302 views

2D Maze Game with Monsters

Introduction I've started to learn C programming a bit and wanted to create a simple 2D console game. Let me first introduce you to the game level/map structure: ...
3 votes
1 answer
119 views

Setting Wallpaper with Xlib and ImageMagick cli

This program reads raw pixels from the pipe/stdin in a loop and set the root window background. ...
1 vote
1 answer
51 views

Archiving MongoDB data to S3, with retryable steps

I have a python script to archive some data (export from mongo to a local json file and then upload it to s3) Is there a better way to implement/improve the current flow? Each step should be be ...
  • 203
3 votes
0 answers
388 views

Android APP FTP downloading file implementation in Java

This is a follow-up question for Android APP connect to FTP server in Java and Android APP FTP uploading file implementation in Java. I am attempting to perform the download operation to specified FTP ...
  • 3,596
1 vote
1 answer
75 views

Open, writing to, and closing a configuration file, and error checking the process in C

All this does is safely and reliably opens, writes to, and closes the file. Yet there are so many gotos and the code is quite verbose. I am not even sure that all ...
5 votes
0 answers
562 views

Exception handling: using @JsonProperty value to make error message

If the validation in RestController fails, I need to handle MethodArgumentNotValidException and provide an errorMessage, that ...
0 votes
1 answer
40 views

SubImage function implementation in C

This is a follow-up question for Two dimensional gaussian image generator in C, Two dimensional bicubic interpolation implementation in C and A SubPlane Method for Generic Two Dimensional Data Plane ...
  • 3,596
1 vote
1 answer
203 views

Android APP FTP uploading file implementation in Java

This is a follow-up question for Android APP FTP host profile class implementation and Android APP connect to FTP server in Java. I am attempting to perform the upload operation to specified FTP ...
  • 3,596
1 vote
1 answer
50 views

Android APP user registration page implementation

This is a follow-up question for Android APP User class implementation. I am attempting to build a user registering system and this post shows the user registration page implementation. The ...
  • 3,596
1 vote
1 answer
56 views

Android APP Password Strength Assessment class implementation

This is a follow-up question for Android APP User class implementation. I am attempting to create a password strength assessment class which is named ...
  • 3,596
3 votes
2 answers
146 views

Custom Error Handler Library in C++

Is this code clean and optimized? When taking memory snapshots, it seems a bit high. Anything I have done wrong or can do to optimize it? ...
1 vote
0 answers
45 views

Access object initialized within try block afterwards if no exception occured

I have a use case where I try to initialize a Player object within a try block. The relevant excerpt of the current, working ...
5 votes
2 answers
3k views

Should i throw exceptions in the service layer or repository, and catch it on the controller? [closed]

I read some answers here on stack exchange, but none really "hits the nail on the head" about where to throw exceptions, where I shouldn't and where to catch them. the idea that an exception ...
1 vote
2 answers
393 views

C ArrayList implementation

I have written a ArrayList class in C and I just wanted some criticism on what I can improve on. Any criticism helps, and I was wondering if there is any better way of doing error handling other than ...
  • 403
-1 votes
1 answer
83 views

Rethrowing unhandled exceptions later in the catching method [closed]

I have a worker class that catches uncaught exceptions and logs them for tracking purposes. However, I do NOT want to swallow those exceptions, nor do I want to abstract them (i.e. losing the stack ...
2 votes
3 answers
260 views

ArrayDowncasters Implementation for Downcasting from System.Array to Array of Specific Type in C#

I am working with System.Array and I am trying to convert System.Array objects to array of specific type (such as ...
  • 3,596
4 votes
1 answer
50 views

Parsing a u8 separated vector of FromStr from a BufRead

I need to read a vector of e.g. integers from a stream, usually from stdin but sometimes also from a file. The input is always less than a megabyte, and is sometimes separated by commas and sometimes ...
1 vote
1 answer
634 views

Read and sort 100 numbers from a text file

The program itself reads 100 values from a text file named input.txt. Then sorts those values in ascending order and writes the values to a new file called ...

1
2 3 4 5
14