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
1answer
80 views

IsDatabaseUp returns true or throws exception

I want to write an ASP.NET Web API endpoint that allows clients to check if database is running. The method below is check if database is up by establishing a connection and running a dummy sql ...
5
votes
1answer
418 views

Swift function to interpret Roman numerals (ported from JavaScript)

I have written some Swift for the first time, being competent enough in Javascript and having some experience in Ruby and Python. For my education, I've written a function that parses a roman numeral ...
4
votes
1answer
5k views

Find all files in directory and subdirectories while ignoring noncritical exceptions

I need to get a list of all files supported by some libary (images) in a specified directory and all subderictories. Root directory of drive might be chosen and in this case I want to skip system ...
4
votes
1answer
121 views

Given a sorted (increasing order) array, write an algorithm to create a binary tree with minimal height

I'm trying to find the complexity of this code and some suggestions for improving the code quality. and handling the code gracefully, esp in the areas of exception handling, checking edge cases, ...
1
vote
1answer
60 views

Ensuring array of worksheets are present

I have a sub which should only continue running if 4 specific worksheets are present. From online reading, such as @Tim Williams's comment in Test or check if sheet exists, I know that using an error ...
6
votes
2answers
2k views

Setter error checking

I have a class called Duration which has the attributes hours, mins, and ...
5
votes
0answers
969 views

Downloading images from Reddit using Python 3

I have been working on this small project in order to fetch top-notch images from Reddit. Overall I am pretty confident about the code below but I am not entirely sure about whether my error handling ...
1
vote
0answers
54 views

Exception handling with recurrency

I writing application that collect job offers from few websites and tries to apply for each joboffer using implementation of this interface for each website: ...
5
votes
3answers
560 views

Recording error messages from an exception

How do I shorten these if else statements? As you can see, those elses are repeated. ...
2
votes
0answers
781 views

RESTful API combining three other APIs

I have created a RESTful API that uses three other APIs with Visual Studio 2017 in .NET Core. It is the first time I have ever programmed in .NET so I am sure the code could use a lot of improvements. ...
3
votes
1answer
3k views

Handling exceptions from async call in synchronous caller

I am using this pattern to easily handle exceptions from async code in a non-async caller. Is this a reasonable thing to do, or am I missing something? In this relatively simply case, I have a ...
6
votes
1answer
67 views

Return true from enumerable that calls function unless that function ever returns false

Is there a tighter way to write this code? ...
0
votes
1answer
90 views

Haskell Servant - login endpoint with two error states

Here is one a handler for dealing with logins, I've recently refactored it to try and make dealing with the different error cases a bit more elegant, though I still think there is room for improvement:...
3
votes
1answer
49 views

Exception handling of HTML parsing

I am currently working on a program that will scrape data from a psych database of various article metadata. Since not every piece is formatted perfectly, I have accepted that some of the info may not ...
1
vote
1answer
54 views

Error handling Beacon scanning

I've recently began trying to put more error handling in to my code so I thought I'd post a use-case to check I'm on the right path. I feel like this is going to make my functions much larger and more ...
3
votes
0answers
157 views

Follow-up: Script to create symlinks for dotfiles in a Git repository

This is a follow up to my previous question on Code Review. I did try to implement most of feedback provided by thiagoalessio. This is what my updated code looks like: ...
4
votes
1answer
696 views

Script to create symlinks for dotfiles in a Git repository

I have a GitHub repository containing all my dotfiles for bash, tmux and neovim. I'm using a ...
1
vote
2answers
83 views

ExitCode class and derived Status class able to return a value

I was thinking about an ExitCode concept in a strict nothrow environment and came up with the following two classes and would like to get some peer review on what flaws they have. They are very simple ...
0
votes
2answers
123 views

Ensuring a non-zero radius when constructing a circle

Is there a little "better" way of writing the line: raise RuntimeError if not radius.is_a? Numeric or radius == 0 I want to only allow numbers bigger than 0. <...
4
votes
1answer
395 views

Read contents of file with appropriate error handling (Rust)

I am trying to learn basic Rust. Is this a good way to get the contents of a file? Am I handling errors the best way? Is there any way this could be more performant? ...
7
votes
1answer
538 views

Errno-like C global error handling

I'm thinking about a unified error handling interface. I've come to conclusion that the errno global variable style isn't so bad, and decided to implement an ...
3
votes
3answers
3k views

SCOPE_EXIT implementation

I'm a fanboy of the Boost library and I've used Boost's components extensively in my C++03 project. The team decided to merge several pieces of code including my project. I will get the C++14 ...
4
votes
3answers
594 views

Using PHP explode() to parse multi-part error messages

I am dealing with a system which sends any unexpected errors back to me in a string, for example: ...
1
vote
1answer
921 views

NullPointer Exception handling in the code [closed]

...
8
votes
1answer
102 views

You're logged in, except it's an error

I've automated downloading of data from a 3rd party website. The process involves logging into the site, downloading the data, then logging out - lather, rinse, repeat for each client. The code is in ...
1
vote
1answer
693 views

utility class for reading in JSON

I'm reasonably happy with the execution: ...
2
votes
1answer
57 views

UnitTest strong exception guarantee

I want to properly test the strong exception guarantee of a method. The method in question is SetFiles. It does not have side-effects (it only modifies the object ...
1
vote
5answers
6k views

Exception handling calculate power

I've to create a class MyCalculator which consists of a single method long power(int, int). This method takes two integers, and, as parameters and finds Math.pow(n,p). - If either n or p is negative, ...
0
votes
1answer
64 views

Report a status based on a list of results

In one of my services, I have the function as presented below: ...
2
votes
1answer
341 views

Is catching null pointer exception to handle it instead of null check beforehand always a bad practice or it depends? [closed]

I wrote a static method for an enum that returns the corresponding enum instance based on the source string, trimming any whitespaces and ignoring case as: ...
2
votes
1answer
324 views

Logging class in Qt library for foreign language calls

I have a small C++/Qt library that interfaces with an application in another language (so interfacing must be performed using primitives, notably pointers to Handler...
2
votes
1answer
327 views

Implementation of OpenGL context

context.h: ...
3
votes
1answer
66 views

Streamlining series of try-except + if-statements for faster loop processing in Python

I'm processing strings using regexes in a bunch of files in a directory. To each line in a file, I apply a series of try-statements to match a pattern and if they do, then I transform the input. After ...
2
votes
1answer
10k views

MySQLi query and error handling for select, insert, and update

I am creating a new webpage with database connection. I want to make sure that I am handling the MySQLi query correctly for Search, Insert, and Update. I also want to make sure if any errors do pop up,...
3
votes
1answer
142 views

TimeoutManager: check whether a task has been finished within a given time

I want to make a helper class, which raises an event whenever something is not finished in a certain time. Example: my program sends out multiple network messages concurrently. After a random delay, ...
3
votes
2answers
4k views

Timeout implementation of fetch

After doing some research on google i didn't find any good info on how to implement timeout with fetch (looks like there are multiple proposals but that's about it so nothing has implemented it). For ...
1
vote
2answers
52 views

Parameter guards for Firebase calls

I have code to ensure parameters existence all over the place. Is there a better way to do it? So that I do not have so many repeated codes inside different functions ...
4
votes
0answers
674 views

Error handling with C-string input using get() and getline()

I've just learned the basics of c-strings and how to read line oriented input. I noticed that fail bits are set for each function. However, not every problem sends a fail bit, so I thought this would ...
1
vote
2answers
11k views

Opening a CSV file in Python, with error handling

Trying to improve my function, as will be used by most of my code. I'm handling most common exception (IOError) and handling when data has no values. ...
1
vote
2answers
113 views

In DRY Python code, when should I catch/raise exceptions? [closed]

Given python's principle of duck-typing, when is it best to raise exceptions? In a simplified case below, say I want to code a couple functions to return booleans based on an input object ...
3
votes
3answers
89 views

Reading and classifying lines from a file

I'm new to C which I'm learning in university now, and I'm not sure if the following is considered in C good practices or not. For an assignment in a simple Classification problem I wrote the ...
2
votes
1answer
3k views

VBA - If error return '0' else execute code

I am converting below excel formula to VBA code and it works as required. =IFERROR(IF(A2="NULL",B2*C2,A2*B2*C2),0) Could someone please review and suggest if ...
1
vote
1answer
54 views

error management when parsing multiple floats

I am writing a handler to render a GIF of a Lorentz attractor. I need to parse floating point numbers from the some querystrings attached to the GIF path. If any of them are bad, I need to log an ...
-1
votes
1answer
5k views

Error handling in a REST API

I have implemented a small REST API using WebApi 2 and NHibernate for ORM. When non-existent id is supplied, NHibernate will throw an InvalidOperationException. So ...
2
votes
1answer
114 views

Function to insert a tag into a database

I'm developing a MVC structured RESTful API project (thanks to the help of Mārtiņš Tereško for explaining it). Almost all of my functions look similar to this: ...
-1
votes
1answer
662 views

Downloading images using a thread pool, with exception handling

I'm currently using a broad Exception handler in my code and I would like to remove this broad exception. Which exceptions should I handle? Are these exceptions generated in my function "func" or ...
3
votes
1answer
152 views

Rspec test to confirm rejection of four invalid dates

...
0
votes
1answer
55 views

Ruby class to encapsulate Retrying (for instance, with email)

One of my clients sends quite a few emails a day ... I would think over 500. They are mostly reports to clients or employees. The volume has become sufficient that intermittent issues with gmail (like ...
1
vote
1answer
1k views

Spring MVC @ControllerAdvice exception handling

This is about handling sql - foreign key constraint failure exceptions (SQL Error: 1452, SQLState: 23000) globally using ...
3
votes
1answer
4k views

MySQL queries with try-except error handling

I have this function that I have written, that gets passed a row of data from a mysql function. The function then uses a try-except block to get some a list of values depending on a value within the ...

1
3 4
5
6 7
16