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 votes
1 answer
54 views

Handling exceptions of FileInputStream and XSSFWorkbook

Can you tear my code apart with code review comments? Below is a simple method which reads an XLSX file and does some stuff with it. I use FileInputStream and ...
AutoTester999's user avatar
1 vote
1 answer
86 views

Two versions of user-specified exception filters that log a different message on match

I'd like to show you two versions of my two functions that support my logging tools. Their purpose is to log a different message (here abort) when an error occured ...
t3chb0t's user avatar
  • 44.2k
0 votes
1 answer
52 views

C interface exception handling with C++ implementation

Whilst developing a bigger project, I was in need of having basic error handling inside the context of a C interface. I came up with the following solution. ...
Sam Coutteau's user avatar
3 votes
1 answer
107 views

Catching the timed out Exception raised by the __init__ method of the class ftplib.FTP

Introduction I have written a Python class which uses the module ftplib. In this class I have created a private method called <...
User051209's user avatar
1 vote
1 answer
60 views

Error Reporting in WPF app

I want to add an error reporting feature to my WPF app. I have the view for it created; I just need to know when to call it. I am used to web development and this is my first WPF app. ...
Henners2002's user avatar
1 vote
1 answer
107 views

A simple parser for bencoding format

I have been learning rust sporadically for a while now and decided to write some toy projects. While browsing https://github.com/codecrafters-io/build-your-own-x I came across some bittorrent client ...
Hakan Sonmez's user avatar
1 vote
0 answers
36 views

I'm writing the command processing part of the tui for a basic task manager/todo list application

The idea is that the TUI struct handles what gets printed to the terminal (I will make it pretty in the future, right now I'm just building its core functionalities) and for processing input. It's ...
dumb_ptr's user avatar
2 votes
1 answer
70 views

Outcome error handler, inspired by boost's outcome namespace

I'm creating a little library for my pet project that is inspired by Boost's outcome namespace. The main reason why I didn't want to use the Boost version is that I don't like the overhead of ...
Goubermouche's user avatar
1 vote
1 answer
127 views

Beginner Java Tic-Tac-Toe

I had a Tic Tac Toe assignment for class and the program seems to work fine but I feel like the exception/input handling could be done in a much better way. Is this a good way to approach the ...
Drosos-kal's user avatar
-3 votes
1 answer
70 views

Catching any exception and actually do something with it [closed]

Say I have a framework, which should catch any exceptions raised from user code, and actually do something with it, such as converting it to a return value ...
user877329's user avatar
4 votes
1 answer
401 views

Write a simple, clean error message without a backtrace and exit on failure

I want to write on failure to either STDOUT or STDERR a clean, simple error message for the user, without the (verbose) ...
Timur Shtatland's user avatar
3 votes
2 answers
241 views

atomic spinlock mutex class

This here is the follow-up to this question. I was recommended to implement a Lockable type (similar to std::mutex) that can work with ...
digito_evo's user avatar
1 vote
1 answer
159 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 ...
t3chb0t's user avatar
  • 44.2k
0 votes
1 answer
116 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 ...
Dan's user avatar
  • 229
3 votes
1 answer
57 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 ...
t3chb0t's user avatar
  • 44.2k
5 votes
4 answers
3k 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. ...
jasmine's user avatar
  • 53
7 votes
2 answers
667 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): ...
digito_evo's user avatar
3 votes
2 answers
98 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 ...
Eoin's user avatar
  • 263
2 votes
4 answers
506 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 ...
Optimus's user avatar
  • 131
2 votes
1 answer
141 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 ...
Patrick Christie's user avatar
2 votes
2 answers
71 views

Stepwise nested pattern mattching with exceptions

Background I'm building a lisp-like toy language in Haskell with the following (stripped down) AST: ...
mingmingrr's user avatar
3 votes
2 answers
145 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. ...
Harith's user avatar
  • 2,302
2 votes
1 answer
180 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 ...
Hrant Nurijanyan's user avatar
0 votes
1 answer
53 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 ...
Neslihan Bozer's user avatar
2 votes
1 answer
46 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 ...
wittgenstein's user avatar
3 votes
1 answer
136 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,...
eddyxide's user avatar
  • 141
2 votes
1 answer
71 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 ...
Dylon Jaynes's user avatar
1 vote
0 answers
220 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 ...
JarsOfJam-Scheduler's user avatar
0 votes
1 answer
241 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 ...
RankinJ's user avatar
1 vote
1 answer
81 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 ...
rdxdkr's user avatar
  • 111
2 votes
1 answer
157 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 ...
Minh Hoang's user avatar
0 votes
2 answers
62 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
244 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 ...
BrDaHa's user avatar
  • 133
1 vote
1 answer
72 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, ...
Yusuf Ipek's user avatar
3 votes
2 answers
307 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
128 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
740 views

Custom string-to-int converter

I have written the following function: ...
digito_evo's user avatar
1 vote
1 answer
1k 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 ...
Pablo Aguirre de Souza's user avatar
3 votes
3 answers
116 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 ...
pacmaninbw's user avatar
  • 23.5k
11 votes
7 answers
3k views

How much error handling is too much?

I have the following C# code (.NET 6): ...
Jessica's user avatar
  • 818
3 votes
1 answer
133 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 ...
JimmyHu's user avatar
  • 3,996
6 votes
1 answer
1k 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 ...
sg7610's user avatar
  • 370
-2 votes
1 answer
74 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, ...
touchofevil's user avatar
5 votes
1 answer
123 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 ...
Dojje's user avatar
  • 51
0 votes
0 answers
53 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 ...
Ramen Enthusiast's user avatar
0 votes
1 answer
304 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: ...
Bart Friederichs's user avatar
-1 votes
1 answer
760 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 ...
cuzureau's user avatar
  • 181
1 vote
2 answers
352 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 ...
AwokeKnowing's user avatar
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 ...
AngelosFr's user avatar
3 votes
1 answer
677 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 ...
JohnLBevan's user avatar
  • 1,409

1
2 3 4 5
15