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
71 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 ...
user avatar
0 votes
2 answers
41 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. ...
user avatar
2 votes
0 answers
33 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 ...
user avatar
  • 133
1 vote
1 answer
39 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, ...
user avatar
3 votes
2 answers
111 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 ...
user avatar
1 vote
1 answer
91 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 ...
user avatar
6 votes
3 answers
655 views

Custom string-to-int converter

I have written the following function: ...
user avatar
1 vote
1 answer
99 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 ...
user avatar
3 votes
3 answers
105 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 ...
user avatar
  • 18.2k
11 votes
7 answers
2k views

How much error handling is too much?

I have the following C# code (.NET 6): ...
user avatar
  • 794
3 votes
1 answer
105 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 ...
user avatar
  • 3,302
6 votes
1 answer
262 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 ...
user avatar
  • 360
-2 votes
1 answer
58 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, ...
user avatar
5 votes
1 answer
69 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 ...
user avatar
  • 51
0 votes
0 answers
38 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 ...
user avatar
0 votes
1 answer
57 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: ...
user avatar
-1 votes
1 answer
157 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 ...
user avatar
1 vote
2 answers
79 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 ...
user avatar
7 votes
5 answers
1k 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 ...
user avatar
3 votes
1 answer
83 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 ...
user avatar
  • 1,329
1 vote
1 answer
83 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 ...
user avatar
  • 3,302
4 votes
1 answer
170 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 ...
user avatar
0 votes
0 answers
37 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 ...
user avatar
  • 3,302
0 votes
1 answer
284 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 ...
user avatar
1 vote
0 answers
67 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 ...
user avatar
  • 3,302
7 votes
2 answers
240 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: ...
user avatar
0 votes
0 answers
58 views

Rust Error Handling - Can this error handling be made cleaner?

Recently I started to learn Rust. I come from a mostly Java background, but spent roughly the last two years in Go. I am working on converting a small microservice that reads data from Kafka and ...
user avatar
  • 145
3 votes
1 answer
90 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. ...
user avatar
1 vote
1 answer
44 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 ...
user avatar
  • 203
3 votes
0 answers
234 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 ...
user avatar
  • 3,302
1 vote
1 answer
67 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 ...
user avatar
5 votes
0 answers
400 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 ...
user avatar
0 votes
1 answer
37 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 ...
user avatar
  • 3,302
1 vote
1 answer
138 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 ...
user avatar
  • 3,302
1 vote
1 answer
46 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 ...
user avatar
  • 3,302
1 vote
1 answer
51 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 ...
user avatar
  • 3,302
3 votes
2 answers
123 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? ...
user avatar
1 vote
0 answers
39 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 ...
user avatar
5 votes
2 answers
2k 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 ...
user avatar
1 vote
2 answers
329 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 ...
user avatar
  • 403
-1 votes
1 answer
80 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 ...
user avatar
2 votes
3 answers
257 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 ...
user avatar
  • 3,302
4 votes
1 answer
47 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 ...
user avatar
1 vote
1 answer
513 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 ...
user avatar
3 votes
1 answer
88 views

Create Table After Deleting Rows Before Desired Range and Filter to Delete All Other Unnecessary Rows

The code below first searches for the first searchText and deletes all rows that precede it to establish a range for a table object. Once the table object is ...
user avatar
3 votes
1 answer
339 views

C++ custom exception handling using std::error_category and std::system_error

I want to make my own custom exception handling and I am curious if I am going the right path, maybe some of you could suggest to me how I could improve it? Or maybe I have went the wrong direction? (...
user avatar
  • 33
3 votes
2 answers
176 views

Library displaying a format with runtime errors, exceptions, and error exceptions present

I have this Library to control errors; I would like if you can evaluate it and make a review of the code, not about the goals of the library: Everything works for me correctly, but I am also open to ...
user avatar
0 votes
1 answer
54 views

C++ Error/exception handling [closed]

I know the following code are horrible, so I'd like a review. Criticism are welcome. I want to know what went wrong, and how I can avoid the same mistake in the future. Version 1 ...
user avatar
2 votes
1 answer
106 views

Modify original JSON few times and post http request

Follow up question from here. I am working on a project where I need to do below things in Python: Take few input parameters like - environmentName, ...
user avatar
  • 169
8 votes
1 answer
272 views

Post json using http and verify whether all actions completed successfully or not

I am working on a project where I need to work with http apis and call them using Python language. Below is what I need to do: Take few input parameters like - <...
user avatar
  • 169

1
2 3 4 5
16