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
1 vote
1 answer
48 views

Protecting functions from empty DataFrames

Pandas likes to throw cryptic errors when you feed its functions with empty DataFrames saying nothing that would help you to identify the root cause. In order to ...
  • 44k
0 votes
1 answer
25 views

Function to return a file name from lists/dictionary constants

I'm reworking a set of two functions that return a text file name, constructed from a string argument and string variables from a module called inventory. It seems ...
  • 229
3 votes
1 answer
49 views

Cancelling function execution with a ContinuationError

Although throwing excptions for control flow is a controversial topic there are some quite popular examples of using this anti-pattern like C#'s async routines throwing the ...
  • 44k
5 votes
4 answers
2k views

Dividing two numbers then handle the divide by zero exception with try/catch

I am new to coding, I hope you can help me to improve my code :) First of all: The code works correctly. ...
  • 53
7 votes
2 answers
484 views

Basic scoped timer struct design

I have written the following simple scoped timer struct in order to help me measure the execution time of arbitrary scopes. Here is the code (live): ...
3 votes
1 answer
48 views

Spring boot shop application with error handling

I'm writing a simple online shop using spring boot, for learning purposes. Right now I have purchasing-service and a product-service. The purchasing-service makes requests to the product-service via ...
  • 263
2 votes
4 answers
312 views

CSV to list, map to database

I have a code block that imports CSV to list and map to a database. And there are few validations and I've to return error messages based on those validations. Right now all those logic is handled by ...
  • 131
2 votes
1 answer
94 views

Command handlers in node.js

Description This javascript code uses tmi.js to listen for chat messages in a Twitch chat and perform certain actions depending on their content. In the sample code ...
2 votes
2 answers
64 views

Stepwise nested pattern mattching with exceptions

Background I'm building a lisp-like toy language in Haskell with the following (stripped down) AST: ...
3 votes
2 answers
128 views

A stripped-down version of UNIX sort utility

Usage: ./usort <options> <filename> Name: ./usort - sort lines of text. Description: Write sorted concatenation of FILE to standard output. ...
  • 929
2 votes
1 answer
108 views

Shader Program OpenGL

I am new to OpenGL learning it on amazing website learnopengl.com I wanted to a convenient way to use shader programs thats why I created this struct, please review it. ShaderProgram.h ...
0 votes
1 answer
48 views

When to use IllegalStateException [closed]

I am implementing an API that implements an interface, but I do not need to implement all methods. In that case, is it better to just return null or throw an IllegalStateException because it if not ...
2 votes
1 answer
40 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
94 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,...
  • 139
1 vote
1 answer
60 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
123 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
119 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
33 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
69 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
85 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
46 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
131 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
57 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
194 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
107 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
702 views

Custom string-to-int converter

I have written the following function: ...
1 vote
1 answer
387 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
111 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 ...
  • 21.9k
11 votes
7 answers
3k views

How much error handling is too much?

I have the following C# code (.NET 6): ...
  • 818
3 votes
1 answer
125 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,768
6 votes
1 answer
866 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
69 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
111 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
49 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
119 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
435 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
127 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
248 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,321
1 vote
1 answer
183 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,768
4 votes
1 answer
362 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
66 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,768
0 votes
1 answer
1k 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
81 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,768
7 votes
2 answers
530 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
176 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
74 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
598 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,768
1 vote
1 answer
80 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
788 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 ...

1
2 3 4 5
15