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
2answers
139 views

Beginning BMI calculator in Java

This is my first program so no doubt I've made mistakes. The code works and meets all requirements as far as I can see. (Further info: program to calculate Body Mass Index (BMI) allowing user to ...
2
votes
0answers
46 views

Implementation of SCPI for control of test instruments

I work with electronics test equipment. I like to be able to automate tests using their remote control interfaces. I have built a pattern, a few base classes, that I can apply to all devices that ...
6
votes
1answer
224 views

Interpret a date from a string of digits

I developed a function that, from a given sequence of digits, extracts the date and reformat it. This is the code: ...
1
vote
1answer
46 views

Handling errors in an input based program

I wrote a program which creates a svg-group that contains several arranged rectangles with passages inbetween to reach all of the rectangles inside of an area selected by the user. Each rectangle ...
0
votes
0answers
29 views

Error handling in Go

I have a function which returns an error. I would like to handle this error on the caller function, so I need to know the reason of the error in the caller function. Below there is my solution, but I ...
4
votes
1answer
180 views

Asynchronous parallel ForEach implemented using Task.Run

I wrote a simple implementation of aysnc parallel.ForEach( ... ) All it really does is create a list of tasks and wait for them all to complete and aggregate the ...
7
votes
2answers
796 views

Python implementation of atoi

I made an implementation of atoi (ascii to integer) in Python a while ago for fun, and I'd like to know what I could do to improve it. ...
1
vote
1answer
72 views

Connect to database, handling errors

I try to handle or catch possible errors with PHP/MySQL for security reasons and would like to know if I'm doing it right. The first case, connection: I use it as a function and call it always when ...
5
votes
2answers
357 views

Single vs Multiple Try Catch

I have this code which is a third-party transfer for ATM console app. For best practice, should I just put all the code into one try block or with multiply try block like below? ...
6
votes
1answer
65 views

A simple but useful error handler

I am trying to make a very simple error handler that would catch and handle all kinds of errors in both development and production environments. The idea is to keep it as simple as possible yet useful ...
3
votes
1answer
203 views

Poor error handling: Throw inside Finally

I have the following code which I am running through fortify. Why it gets marked for poor error handling, throw inside finally? ...
7
votes
2answers
298 views

Network helper class with retry logic on failure

I wrote an helper class which allow me to request the body content from a site that is created by AJAX, for doing so I'm using <...
2
votes
1answer
41 views

Blocking requests within Express

Is this the correct way to block requests in Express? app.js ...
2
votes
2answers
54 views

PHP display Error Wanings Yellow @ bottom of Page with PHP_EOL

I initially started searching for a PHP script which would output PHP errors, to the JavaScript console. As the Default behaviour is just to spit them out anywhere and displace everything else. ...
1
vote
1answer
37 views

Clean up code that transfers data from DB2 Server to Excel

The code below is functional and works as expected, but I imagine there is a better way to test for the error that I am testing for . The scenario is that data is transferred between two different ...
2
votes
1answer
77 views

Go functions to create a directory if it doesn't exist

Which of the 2 solutions is written better? Personally I prefer the one line method but it does make it slightly more difficult to debug. Is perhaps doing it the long way first then refactoring to ...
11
votes
3answers
3k views

C# TCP server/client class

Goal My goal is to create a TCP server/client class that can be universally reused in various private projects. It should work stable and does not need to be super fast, but rather light-weight to ...
10
votes
1answer
104 views

error-specific tryCatch

R doesn't have classed errors, just (for the most part) error and warning, so determining if the error should be caught or ...
2
votes
1answer
55 views

PHP function to check if something valid or return error message [closed]

I would like to make a function that checks if something is valid, but if it can't then I want to return an error message that will probably be used to to throw an exception. ...
3
votes
1answer
36 views

Validating partially filled objects

The following classes are a simplification of an auto-generated code of an ORM (targeting Microsoft's Dynamics CRM): ...
-1
votes
1answer
66 views

Try-catch-finally snippet [closed]

Using visual studio I created a snippet which helps me surround my already written or new code into a try-catch-finally block. I use axios for REST so there had to be separate error handling method so ...
2
votes
2answers
71 views

Jsoup connection to URL

I have simple class that I want to ask if is there any possible to improve it? I mean, for me it looks poor. Is there any way to use here try-with-resources, stream or ...
1
vote
0answers
59 views

AWS plugin to create a CloudFormation stack if it doesn't exist

The following Python class is what I am trying to refactor in the case where I have to add validation of the existence of an AWS cloudformation stack before creating it in the method create_cfn_stack :...
2
votes
0answers
17 views

Error handling in express without middlewares and using class structure

This is a simple implementation of Django's sample project "Poll" using and express. The controller code: ...
5
votes
1answer
126 views

Detecting the presence of multiple URL segments

I have two versions of a function that performs the same task, however I'm not sure which one to use. Speed is something to take into consideration, but I also want to know what the best practice is. ...
3
votes
3answers
959 views

Go function to test whether a file exists [closed]

How could one write in a more elegant way that if error is null, the result is true? I really need a bool as returned value. ...
4
votes
1answer
48 views

Send / receive wrapper for System.Net.Sockets - follow-up

I recently posted a question about improving thread and socket safety in my NetworkEndpoint class. previous post I have implemented the changes suggested in the answer I got there. When I asked for a ...
0
votes
1answer
26 views

Enumerating AWS instances in Rails, with error handling

I have created a method, which is raising the same exception in case of any error: ...
7
votes
3answers
533 views

Compiling all Exception messages into a string

Below is a recursive function I've written that's responsible for compiling a string consisting of a Exception's message, and also each of that ...
6
votes
1answer
95 views

Send / receive wrapper for System.Net.Sockets

The following NetworkEndpoint class serves as a simple send / receive interface for either side of a network connection (client or server) when provided with a ...
9
votes
4answers
1k views

Skipping over failed imports until they are needed (if ever)

We have a program with many dependencies. Because the user may not want to use all of them, the program should skip over failed imports and only raise an error if absolutely necessary. e.g. if the ...
0
votes
0answers
23 views

Complexity of a service method to fetch search results from an API

I tried the plug in CodeMetrics for Visual Studio Code along with some of my current Angular projects, and I was a little suprised about the outcome. I have a ...
3
votes
1answer
97 views

PHP Error handler class

I set up an error handler class to handle all server errors, I know there are already quite a few out there, but I like creating my own for better learning and understanding of how things work. I am ...
-4
votes
1answer
53 views

What is wrong with my 'except' code here? [closed]

I am learning python and am working through some try and except codes. What is wrong here? The code aims to convert the input ...
3
votes
0answers
48 views

msmq bulk send in c# [closed]

Please review the code below and provide constructive feedback to improve. Multiple threads call the SendMessageToMSMQ method to send messages to a msmq queue. ...
2
votes
0answers
15 views

Thread safe Shareable and Splittable Buffer with Safe Memory (Project)

Backstory This is a buffer I wrote for use in multiple personal projects. It is designed to handle pretty much any data in pretty much any way. In particular I intend to use it in such instances as ...
2
votes
1answer
73 views

Should I re-throw exceptions within a method, or is there a better way to handle it? [closed]

When handling errors in C#, is it acceptable/appropriate to re-throw exceptions that are caught in a try/catch? My scenario is that I am making an HTTP request and ...
3
votes
0answers
92 views

Async in Railway Oriented Programming in F#

In F# the Railway Oriented Programming pattern can be implemented synchronously using the Result<'t,'terr> type as result value for functions, so they can be ...
2
votes
1answer
46 views

PHP LDAP credentials validation and error handling

I developed this group of scripts to validate users againts a LDAP server and presenting the appropiate message to the user after sending the information. I wonder if I'm handling everything properly ...
4
votes
2answers
79 views

Thread-safe stack in Java with fixed capacity

Implement a multi-threaded stack, with freedom to use existing implementations of stack. On top of being thread-safe, it must block (not busy-wait) a pushing thread when stack is full and a ...
2
votes
2answers
69 views

Validating that a Java program has two equal-length arguments

I'm writing a small almost one method Java class for a job application and the advice given was to write it as though it was a piece of commercial software. The ...
5
votes
1answer
40 views

Typescript monad for data being loaded

I have been struggling to make typescript happy about the types. I am pulling data from our backend API and I wanted to give context to the data. Basically it is a monad with 4 shapes: Initial (...
3
votes
1answer
57 views

Interactive command-line binary to decimal converter

Is this the most efficient way to write this piece of code? Is there a better way of handling errors inside of a while/for loop, instead of calling back to the original function? I have tried using <...
3
votes
1answer
73 views

Get result from form website operation

I want to get a result from the website when I submit a form. There are several things that can go wrong. In a simple scenario I want to return: true - when ...
2
votes
1answer
72 views

Exception, errors handling, best practice in WebApi Core

I'm making my WebApi project. My logic is, the controller didn't see data. It only triggers a service that returns objects to it. My simple method from ...
3
votes
2answers
58 views

Generic function that accepts both Actions and Func's as parameters

I've created a generic try catch I can apply throughout my code so I'm not repeating myself. ...
0
votes
0answers
29 views

Making Oauth request asynchronously, with retry if token has expired

I'm struggling with asynchronous code. Does anyone have suggestions of a better way to do the following? What I'm doing: hitting an API (google's, actually), with a call that might get a 401 if the ...
4
votes
1answer
94 views

Wrap a callback method in an awaitable method

I'm using a .NET library which uses a pre-async/await type of asynchronicity. That is, it provides asynchronous (non-awaitable) method with a callback parameter. I'm trying to write awaitable ...
4
votes
0answers
37 views

Python: Exception handling in a logic gate

I'm learning about Python and am going through the OO-stage where I'm building a set of logic-gate classes. To make the logic more resilient, I only want the user to be able to enter a value of 0 or ...
3
votes
0answers
111 views

Copying content from Excel into PowerPoint as a picture, with error handling

The code below works, but I want to ask if my solution is adequate or if there's something I should structure differently. If it's alright, I'll apply the same code in other subs. My code copies ...